Q. Find the kth largest element in an array
asked 2xmediumArraysOnline test, Technical2024
Ans. Use Quickselect to find the Kth largest element by partitioning the array around a pivot and only recursing into the side that can contain the answer. Convert it to the index n minus k in sorted ascending order. Average time is O(n), worst case O(n²), with O(1) extra space.
Q. Rearrange characters in a string such that no two adjacent characters are the same.
asked 2xmediumStringsTechnical2020
Ans. Use a greedy max heap of character frequencies: repeatedly take the two most frequent remaining characters, append both, decrement their counts, and push back any still left. This avoids placing equal characters together. The key feasibility check is that no character may appear more than (n + 1) / 2 times. Time is O(n log k).
Q. Check whether a given string is a palindrome
asked 2xeasyStringsTechnical2023-2024
Ans. Use two pointers, one at the start of the string and one at the end, and compare characters while moving inward. If any pair differs, it is not a palindrome; if the pointers meet or cross, it is. This uses no extra data structure and runs in O(n) time with O(1) space.
Q. Find the maximum sum subarray in an array using Kadane’s Algorithm
asked 2xeasyArraysOnline test2023-2024
Ans. Use Kadane’s Algorithm by scanning the array once, keeping a current sum and a best sum seen so far. At each element, set current sum to the larger of the element itself or current sum plus the element, then update best sum. It uses only variables, runs in O(n) time, and O(1) space.
Q. How can you cut a round cake into 8 equal pieces using only 3 cuts?
asked 2xeasyLogical reasoningTechnical2019-2020
Ans. Make two straight cuts down through the cake at right angles, crossing in the centre. This gives four equal quarter pieces. Then make the third cut horizontally through the middle of the cake, parallel to the table. That splits each quarter into two equal layers, giving 8 equal pieces in total.
Q. Explain core Object-Oriented Programming concepts such as inheritance, polymorphism, encapsulation, and abstraction
asked 2xeasyOOPTechnical2023-2024
Ans. Core OOP concepts are inheritance for reusing and extending behaviour, polymorphism for using different object types through a common interface, encapsulation for hiding internal state, and abstraction for exposing only essential details. The key idea is modelling software as objects with clear responsibilities, making code easier to change, test, and maintain.
Q. Given an array of integers and a number sum, find the number of pairs of integers in the array whose sum is equal to sum.
asked 2xeasyArraysOnline test2019-2020
Ans. Use a hash map of frequencies and scan the array once, counting how many previous numbers equal sum minus the current number. Then add the current number to the map. This correctly handles duplicates and avoids counting a pair twice. The time complexity is O(n), with O(n) extra space.
Q. Design a TinyURL service
asked 1xmediumUrl shortenerSystem design2024
Ans. Build a service that maps a short code to a long URL, with APIs to create and resolve links. Generate a unique numeric ID, encode it in Base62, store code to URL in a durable key value store, and cache hot redirects. Use replication, rate limits, expiry support, and analytics as optional extensions.
Q. What is the String Pool in Java?
asked 1xmediumOOPTechnical2021
Ans. The Java String Pool is a special area on the heap where Java stores unique String literals. When the same literal appears again, Java reuses the existing String object instead of creating a new one. This saves memory, but it also means == may be true for pooled strings, while equals checks content.
Q. Explain indexing in DBMS and its types.
asked 1xmediumDBMSTechnical2022
Ans. Indexing in DBMS is a technique that creates a separate data structure to find rows faster without scanning the whole table. Common types include primary index, secondary index, clustered index, non-clustered index, dense index, and sparse index. Indexes speed up reads but add storage cost and slow inserts, updates, and deletes.
Q. Find the median of a stream of integers.
asked 1xmediumHeapsTechnical2021
Ans. Use two heaps: a max heap for the lower half of numbers and a min heap for the upper half. Keep their sizes equal, or let the max heap have one extra element. Insert into the correct heap, then rebalance. The median is the max heap top, or the average of both tops. Insert is O(log n), median is O(1).
Q. Implement a cache of a given fixed size.
asked 1xmediumDesignTechnical2020
Ans. Implement it as an LRU cache using a hash map plus a doubly linked list. The hash map gives O(1) access to entries, and the list keeps recency order. On get or put, move the entry to the front. When capacity is exceeded, remove the tail entry in O(1).
Q. Print all permutations of a given string.
asked 1xmediumStringsTechnical2022
Ans. Use backtracking to build permutations by choosing each unused character in turn, recursing until the current string has the original length, then print it. Keep a character array, a boolean used array, and a temporary result buffer. The time complexity is O(n × n!) and the recursion depth is O(n).
Q. Design an e-commerce system like Flipkart.
asked 1xmediumScalabilityHR2021
Ans. Build it as microservices for catalogue, search, cart, orders, payments, inventory, users and delivery, behind an API gateway and load balancers. Use caching and search indexes for fast browsing, relational storage for orders and payments, and event queues for checkout, stock updates and notifications. The key detail is strong inventory consistency during ordering.
Q. How are maps internally implemented in C++?
asked 1xmediumOOPTechnical2022
Ans. std::map is usually implemented as a self-balancing binary search tree, most commonly a red-black tree. It stores key-value pairs ordered by key, so lookup, insertion and deletion take logarithmic time. Iterators traverse elements in sorted order and usually remain valid unless their own element is erased.
Q. Design a coffee ordering system (HLD and LLD)
asked 1xmediumApplication designSystem design2024
Ans. Design it with clients, order service, menu service, payment service, notification service, and a queue-driven fulfilment service for baristas. Model MenuItem, Order, OrderItem, Payment, Customer, Store and OrderStatus. The key detail is state management: orders move from created to paid, preparing, ready and completed, with idempotent payments and events between services.
Q. Implement the LRU (Least Recently Used) Cache.
asked 1xmediumLinked listsTechnical2020
Ans. Use a hash map plus a doubly linked list. The map gives O(1) access to cache nodes by key, and the list keeps usage order, with most recent at the front and least recent at the back. On get or put, move the node to the front. When capacity is exceeded, remove the back node.
Q. Solve and code a problem using Priority Queue.
asked 1xmediumHeapTechnical2024
Ans. Use a priority queue when you repeatedly need the smallest or largest available item, such as finding the kth largest element. Maintain a min heap of size k, push each number, and remove the smallest when size exceeds k. The heap top is the answer. Time complexity is O(n log k), space is O(k).
Q. Find the level with maximum sum in a binary tree.
asked 1xmediumTreesTechnical2022
Ans. Use level order traversal and compute the sum of each level, keeping the level with the largest sum seen so far. A queue is the key data structure: process all nodes currently in the queue as one level, enqueue their children, then compare that level’s sum. Time is O(n), space is O(w).
Q. Find an element in a sorted infinitely long array.
asked 1xmediumBinary searchTechnical2021
Ans. Use exponential search to find a finite range containing the target, then run binary search inside that range. Start with index 1 and keep doubling while the value is less than the target. Once arr[i] is at least the target, binary search between i/2 and i. Time complexity is O(log p), where p is the target position.
Q. Print all balanced parentheses from a given string.
asked 1xmediumBacktrackingOnline test2019
Ans. Scan the string once and use a stack to store indices of unmatched opening brackets. When a closing bracket is found and the stack is not empty, pop one opening index and mark both positions as balanced. Finally, print only marked brackets in original order. This takes O(n) time and O(n) space.
Q. Explain scalability considerations in system design.
asked 1xmediumScalabilityTechnical2019
Ans. Scalability means designing a system so it can handle growth in users, traffic, data and workload without unacceptable latency, cost or failure rates. The key consideration is removing bottlenecks by using horizontal scaling, load balancing, caching, database partitioning, asynchronous processing, stateless services and clear monitoring of capacity limits.
Q. Search for an element in a sorted and rotated array.
asked 1xmediumBinary searchTechnical2020
Ans. Use a modified binary search: compare the middle element with the ends to decide which half is sorted, then check whether the target lies inside that sorted half. If it does, search there, otherwise search the other half. For distinct elements, this takes O(log n) time and O(1) space.
Q. How is React different from other frontend frameworks?
asked 1xmediumFrontendTechnical2024
Ans. React is different because it is mainly a UI library, not a full frontend framework. It focuses on building reusable components and updating the view declaratively when state changes. Unlike more opinionated frameworks, React leaves routing, data fetching and project structure to separate libraries, giving flexibility but requiring more architectural choices.
Q. What is database normalization and what are its types?
asked 1xmediumDBMSTechnical2021
Ans. Database normalization is the process of organising relational database tables to reduce duplication and avoid update, insert, and delete anomalies. The main forms are 1NF, which removes repeating groups; 2NF, which removes partial dependency; 3NF, which removes transitive dependency; and BCNF, which enforces stricter dependency rules.
Q. Reverse a doubly linked list in groups of given size k.
asked 1xmediumLinked listsTechnical2021
Ans. Reverse each block of k nodes by swapping every node’s next and prev pointers, then connect the reversed block to the result of reversing the remaining list. The key detail is to preserve the next block’s start before relinking. This uses the existing doubly linked list nodes, runs in O(n) time, and uses O(1) extra space if iterative.
Q. Find the longest substring without repeating characters.
asked 1xmediumStringsTechnical2023
Ans. Use a sliding window with two pointers and a map from character to its last seen index. Move the right pointer through the string, and when a repeated character appears inside the current window, move the left pointer past its previous position. Track the maximum window length. Time complexity is O(n), space is O(min(n, charset)).
Q. Rotate an m x m matrix by 90 degrees clockwise in-place.
asked 1xmediumArraysTechnical2015
Ans. Transpose the matrix in-place, then reverse each row in-place. The transpose swaps elements across the main diagonal, and reversing rows moves each column into its clockwise-rotated position. This uses only swaps, so it needs O(1) extra space and O(m²) time for an m by m matrix.
Q. Connect N ropes with minimum cost using a greedy approach
asked 1xmediumGreedyOnline test2021
Ans. Use a greedy approach by always connecting the two shortest ropes first, adding their combined length to the total cost, then putting the new rope back. A min heap is the key data structure, because it gives the two smallest ropes efficiently. Repeat until one rope remains. Time complexity is O(n log n).
Q. When you search a URL in a browser, how is data received?
asked 1xmediumNetworkingTechnical2021
Ans. The browser receives data as an HTTP or HTTPS response from the server, usually broken into TCP packets and reassembled by the network stack. First it resolves the domain with DNS, opens a TCP connection, negotiates TLS for HTTPS, sends a request, then downloads HTML, CSS, JavaScript and other resources to render the page.
Q. Find the next greater number using the same set of digits.
asked 1xmediumStringsTechnical2020
Ans. Scan digits from right to left to find the first digit smaller than the digit after it. Swap it with the smallest larger digit to its right, then sort or reverse the suffix into ascending order. If no such digit exists, no greater number is possible. This is the next permutation algorithm, O(n) time.
Q. Find the size of the largest island in a 2-D binary matrix.
asked 1xmediumGraphsOnline test2020
Ans. Use DFS or BFS to scan every cell, and when you find an unvisited 1, explore its whole island and count its cells. Track the maximum count seen. Use a visited matrix or mark cells in place. With four-directional adjacency, the time complexity is O(rows × cols) and space is O(rows × cols).
Q. Explain deadlocks in Operating Systems and related concepts.
asked 1xmediumOperating systemsTechnical2022
Ans. A deadlock is a state where two or more processes wait forever because each holds a resource another needs. It requires mutual exclusion, hold and wait, no pre-emption, and circular wait. Systems handle it by prevention, avoidance such as Banker’s algorithm, detection and recovery, or ignoring it when rare.
Q. Explain abstraction, interfaces, and friend functions in C++.
asked 1xmediumOOPTechnical2021
Ans. Abstraction hides implementation details and exposes only essential behaviour; interfaces define the operations a type promises to provide; friend functions are non-member functions allowed to access a class’s private and protected members. In C++, abstraction is usually achieved with classes and pure virtual functions, while friendship should be used sparingly because it weakens encapsulation.
Q. Find the Longest Common Subsequence (LCS) between two strings.
asked 1xmediumDynamic programmingOnline test2019
Ans. Use dynamic programming with a 2D table where dp[i][j] stores the LCS length for the first i characters of one string and first j of the other. If characters match, add one from dp[i-1][j-1]; otherwise take the maximum of top or left. Time and space are O(nm).
Q. Find the row with the maximum number of 1s in a binary matrix.
asked 1xmediumArraysTechnical2021
Ans. Start from the top right cell and move left when you see a 1, updating the answer row, or move down when you see a 0. For a row-wise sorted binary matrix, this finds the row with the most 1s in O(rows + columns) time and O(1) space.
Q. How would you estimate the total number of buses in your city?
asked 1xmediumEstimationManagerial2022
Ans. I would estimate from service needs. Suppose the city has 2 million people and 10% ride buses at peak, so 200,000 trips. If one bus carries 60 people and makes about 2 peak trips, that needs around 1,700 active buses. Adding 20% for maintenance and spares gives about 2,000 buses.
Q. What is the difference between HashMap, Hashtable, and TreeMap?
asked 1xmediumCollectionsTechnical2021
Ans. HashMap is an unordered hash-based map, Hashtable is a legacy synchronised hash-based map, and TreeMap is a sorted map backed by a red-black tree. HashMap allows one null key and null values, Hashtable allows neither, and TreeMap orders keys naturally or by comparator. HashMap is usually O(1), TreeMap O(log n).
Q. Write an SQL query involving data manipulation and optimization.
asked 1xmediumSQLOnline test2024
Ans. Use an update joined to a filtered subquery: select the target rows with a where clause, join by indexed keys, then update only those rows. The main optimisation is a B-tree index on the join and filter columns, so lookup is logarithmic rather than scanning the whole table.
Q. Given an array, print all triplets (a, b, c) such that a + b = c.
asked 1xmediumArraysTechnical2020
Ans. Use a hash set or frequency map, then check every pair a and b and see whether a + b exists as c. Print the triplet only if the required occurrence is available and indices are distinct. This takes O(n²) time and O(n) extra space, and works without sorting.
Q. How would you handle situational challenges or decisions at work?
asked 1xmediumConflict resolutionHR2023
Ans. Pick a real situation where priorities, people, or risk were in tension. Emphasise how you gathered facts, involved the right people, weighed options, made a decision, and communicated it clearly. Interviewers listen for calm judgement, ownership, flexibility, ethical thinking, and what you learned from the outcome.
Q. Write a SQL query to remove duplicate rows from a database table.
asked 1xmediumSQLTechnical2021
Ans. Use a delete with a common table expression that assigns ROW_NUMBER to each duplicate group, then delete rows where the row number is greater than one. Partition by the columns that define duplication, and order by a stable key to keep one row. It typically needs sorting, so time is about n log n.
Q. Search for an element in a row-wise and column-wise sorted matrix.
asked 1xmediumArraysTechnical2019
Ans. Start from the top-right element and eliminate one row or one column at a time. If the current value equals the target, return found. If it is greater, move left. If it is smaller, move down. This works because rows and columns are sorted. Time complexity is O(m + n), space is O(1).
Q. Given a string, determine whether it represents a valid IP address.
asked 1xmediumStringsTechnical2022
Ans. Split the string by dots and check that it has exactly four parts. Each part must be non-empty, contain only digits, have no leading zero unless it is exactly “0”, and convert to a value between 0 and 255. No special data structure is needed. The time complexity is O(n).
Q. Justify a chosen technology stack and explain reasons for using it.
asked 1xmediumTechnical communicationHR2023
Ans. Choose a real project where the stack clearly matched business and technical needs. Explain the constraints, such as speed, scale, team skills, budget, security, integrations, or maintainability. Emphasise trade-offs, not personal preference. Interviewers listen for evidence you can make pragmatic decisions, compare alternatives, manage risk, and justify technology choices commercially.
Q. What are the different ways to create or implement threads in Java?
asked 1xmediumOperating systemsTechnical2021
Ans. In Java, threads are commonly created by extending Thread, implementing Runnable, implementing Callable with a Future, or submitting tasks to an ExecutorService. The preferred approach is usually Runnable or Callable with an executor, because it separates the task from the thread and allows pooling, reuse, results, and better lifecycle management.
Q. Print the 360-degree view (top view + bottom view) of a binary tree.
asked 1xmediumTreesTechnical2020
Ans. Print all nodes visible in either the top view or bottom view, ordered by horizontal distance. Do a level order traversal with each node’s horizontal distance, using a map from distance to first seen node for top view and last seen node for bottom view. Merge them, avoiding duplicates. Time complexity is O(n log n).
Q. Write code to demonstrate a deadlock in a multithreaded environment.
asked 1xmediumOperating systemsTechnical2015
Ans. Create two threads and two mutex locks. Thread A locks mutex 1, sleeps briefly, then tries to lock mutex 2. Thread B locks mutex 2, sleeps briefly, then tries to lock mutex 1. Each waits forever for the other lock, causing deadlock. The key detail is inconsistent lock ordering. Setup is O(1).
Q. Explain the internal implementation of HashMap and write code for it.
asked 1xmediumOOPTechnical2015
Ans. A HashMap is implemented as an array of buckets, where a key’s hash code is transformed into an index to store the key value entry. If multiple keys map to the same bucket, collisions are handled using a linked list or, in modern Java, a balanced tree after a threshold. Resizing happens when the load factor is exceeded.
Q. How would you implement a bidding system and increase its robustness?
asked 1xmediumScalabilityHR2021
Ans. I would implement bidding with an append-only bid log, a strongly consistent write path, and a materialised current-highest-bid view. Each bid uses an idempotency key, validation, and optimistic locking or a conditional database update to prevent races. Robustness comes from retries, message queues, audit logs, monitoring, rate limits, and clear failure recovery.
Q. How do automation tools like workflows and triggers work in Salesforce?
asked 1xmediumSalesforceTechnical2024
Ans. Salesforce automation runs business logic when records are created, updated, deleted, or meet defined conditions. Workflows are declarative rules that perform actions such as field updates, emails, tasks, or outbound messages. Triggers are Apex code that runs before or after database events and are used for more complex logic that workflows cannot handle.
Q. Add two numbers represented by two arrays and return the resulting array.
asked 1xmediumArraysTechnical2022
Ans. Add from the end of both arrays, digit by digit, keeping a carry, and build the result digits in reverse order. Use a dynamic array or list for the result, then reverse it at the end, or prepend carefully. Continue while either array has digits or carry remains. Time complexity is O(n + m).
Q. Find the length of the longest valid (well-formed) parentheses substring.
asked 1xmediumStacksTechnical2022
Ans. Use a stack of indices to find the maximum length of a valid parentheses substring in linear time. Push -1 first as the base. For each '(', push its index. For each ')', pop; if the stack becomes empty, push the current index, otherwise update the answer with current index minus stack top.
Q. Given a grid of oranges, find the minimum time required to rot all oranges.
asked 1xmediumGraphsOnline test2020
Ans. Use multi-source BFS starting from all initially rotten oranges, and count levels as minutes. Put every rotten orange in a queue, spread to adjacent fresh oranges, and decrement the fresh count. The result is the BFS time if no fresh oranges remain, otherwise return -1. Time complexity is O(rows times columns).
Q. Write Java code to demonstrate polymorphism in Object-Oriented Programming.
asked 1xmediumOOPTechnical2023
Ans. Use a superclass or interface such as Animal with a makeSound method, then create Dog and Cat classes that override it. Store Dog and Cat objects in a List<Animal> and call makeSound on each reference. Java chooses the correct overridden method at runtime. Iterating the list is O(n); each call is effectively O(1).
Q. Solve the 9 balls puzzle to find the odd ball in the minimum number of steps.
asked 1xmediumLogical reasoningTechnical2021
Ans. Minimum is two weighings if the odd ball is known to be heavier or lighter. Split the balls into three groups of three. Weigh group A against group B. If they balance, the odd ball is in group C; otherwise it is in the heavier or lighter group. Weigh one ball against another within that group to identify it.
Q. Role-play scenario where you act as a support engineer handling a customer issue.
asked 1xmediumConflict resolutionHR2021
Ans. Choose a realistic incident where you owned the customer experience, not just the technical fix. Emphasise calm questioning, empathy, clear triage, setting expectations, checking logs or data, escalating when needed, and closing the loop. Interviewers listen for structure, communication under pressure, sound troubleshooting, accountability, and evidence that you protect customer trust.
Q. Find the angle between the hour hand and minute hand of an analog clock at a given time (e.g., 3:15)
asked 1xmediumLogical reasoningTechnical2015
Ans. Convert both hands to degrees from 12 o’clock. The minute hand is 6 degrees per minute. The hour hand is 30 degrees per hour plus 0.5 degrees per minute. Find the absolute difference, then use the smaller angle: min(difference, 360 minus difference). At 3:15, the angle is 7.5 degrees.
Q. Calculate compound interest for a given principal, rate, and time.
asked 1xeasyProbabilityTechnical2019
Ans. Use the formula A = P(1 + r/100)^t, where P is principal, r is annual interest rate, and t is time in years. Compound interest is A minus P. If interest is compounded more than once per year, use A = P(1 + r/100n)^(nt), where n is compounding frequency.
Q. Find the angle between the hour hand and the minute hand of a clock at 3:15.
asked 1xeasyLogical reasoningHR2020
Ans. The angle is 7.5 degrees. To solve clock-angle problems, place 12 at 0 degrees. The minute hand moves 6 degrees per minute, so at 15 minutes it is at 90 degrees. The hour hand moves 30 degrees per hour plus 0.5 degrees per minute, so it is at 97.5 degrees.
Showing 60 of 309 questions. Ranked by how often the same question came back across interviews.