Q. Reverse a linked list
asked 7xeasyLinked listsOnline test, Technical2014-2023
Ans. Reverse a linked list by iterating through it and changing each node’s next pointer to point to the previous node. Keep three pointers: previous, current, and next, so you do not lose the rest of the list. At the end, previous is the new head. Time complexity is O(n), space complexity is O(1).
Q. Reverse a singly linked list.
asked 5xeasyLinked listsOnline test2014-2016
Ans. Reverse it by walking through the list once and redirecting each node’s next pointer to the previous node. Keep three pointers: previous, current, and next, so you do not lose the remaining list. At the end, previous becomes the new head. Time is O(n), space is O(1).
Q. Difference between process and thread
asked 5xeasyOperating systemsManagerial, System design, Technical2012-2019
Ans. A process is an independent running program with its own memory space, while a thread is a smaller unit of execution within a process that shares that process’s memory. Processes are more isolated and cost more to create or switch between. Threads are lighter, but shared memory makes synchronisation and race conditions important.
Q. Explain virtual memory and paging
asked 4xmediumOperating systemsTechnical2014-2020
Ans. Virtual memory is an abstraction that gives each process its own large, private address space, independent of physical RAM. Paging implements this by splitting virtual memory and physical memory into fixed-size pages and frames. A page table maps virtual pages to frames, and missing pages can be loaded from disk on demand.
Q. Check if a number is a palindrome
asked 4xeasyMathOnline test2014-2016
Ans. A number is a palindrome if it reads the same forwards and backwards, such as 121. Handle negatives as not palindromes, then reverse only the second half of the digits and compare it with the first half. This avoids string conversion and reduces overflow risk. Time complexity is O(log n), with O(1) space.
Q. Print a given matrix in spiral order
asked 4xeasyArraysOnline test, Technical2018-2020
Ans. Traverse the matrix layer by layer using four boundaries: top, bottom, left, and right. Print the top row, right column, bottom row, and left column, then move the boundaries inward. No extra data structure is needed apart from the output. Time complexity is O(mn), and space is O(1).
Q. Check whether a given number is a palindrome.
asked 4xeasyMathOnline test2014-2016
Ans. A number is a palindrome if it reads the same forwards and backwards. Handle negatives as not palindromes, then reverse the digits numerically, or reverse only half to avoid overflow, and compare with the original or remaining half. No data structure is needed. Time complexity is O(d), space complexity is O(1), where d is digit count.
Q. Find the median of a stream of running integers.
asked 3xmediumHeapsTechnical2019-2020
Ans. Use two heaps: a max heap for the lower half of numbers and a min heap for the upper half. Insert each new number into the correct heap, then rebalance so their sizes differ by at most one. The median is the larger heap’s top, or the average of both tops. Insert is O(log n), median is O(1).
Q. Multiply two numbers without using the * operator using minimum number of additions
asked 3xmediumMathOnline test2014-2016
Ans. Use binary multiplication: make the multiplier the smaller absolute number, repeatedly halve it, double the other number, and add the doubled value to the result only when the current multiplier bit is 1. Handle the sign separately. This uses O(log min(a, b)) steps and far fewer additions than repeated addition.
Q. Check if a given sum exists in an array
asked 3xeasyArraysOnline test2014-2016
Ans. Use a hash set to check whether any two elements add up to the given sum. Scan the array once; for each element, compute the needed complement and check if it is already in the set. If yes, the sum exists. Otherwise, insert the element. Time complexity is O(n), space complexity is O(n).
Q. Find the middle element of a linked list
asked 3xeasyLinked listsOnline test, Technical2013-2024
Ans. Use two pointers: move a slow pointer one node at a time and a fast pointer two nodes at a time. When the fast pointer reaches the end, the slow pointer is at the middle. This uses no extra data structure, runs in O(n) time, and O(1) space.
Q. Check if the given parentheses string is balanced.
asked 3xeasyStackOnline test2015-2016
Ans. Scan the string left to right and use a stack to ensure every closing bracket matches the most recent unmatched opening bracket. Push opening brackets, pop and compare on closing brackets, and fail if the stack is empty or mismatched. The string is balanced only if the stack is empty at the end. Time complexity is O(n).
Q. What is Belady's anomaly?
asked 2xmediumOperating systemsTechnical2019-2020
Ans. Belady’s anomaly is the counterintuitive case where giving a process more page frames causes more page faults, not fewer. It is most commonly seen with the FIFO page replacement algorithm. Stack-based algorithms such as LRU and optimal replacement do not suffer from it because their resident page sets grow monotonically.
Q. Design an Elevator system.
asked 2xmediumObject oriented designSystem design2017-2019
Ans. Design it as controllers managing elevators, requests and scheduling, with each elevator tracking current floor, direction, state, capacity and assigned stops. The key detail is the dispatch algorithm: group requests by direction and allocate the nearest suitable elevator, while each elevator serves stops in order before reversing, minimising wait and travel time.
Q. 21 matchstick puzzle and its variants
asked 2xmediumGame theoryTechnical2017
Ans. With 21 matches, taking 1 to 4, and the last match losing, the first player cannot force a win. The losing counts are 1, 6, 11, 16, 21, spaced by 5. The second player always replies with 5 minus the first player’s pick. If last match wins, the first player takes 1, then uses the same reply rule.
Q. Print the right view of a binary tree
asked 2xmediumTreesTechnical2016-2020
Ans. Use level order traversal and print the last node seen at each level. Keep a queue of nodes, process one level at a time using the current queue size, and record or print the node when it is the last in that level. Time complexity is O(n), and space complexity is O(w).
Q. Detect and remove a loop in a linked list
asked 2xmediumLinked listsTechnical2016-2020
Ans. Use Floyd’s slow and fast pointer method to detect the loop, then remove it by finding the node where the cycle starts and setting the previous node’s next pointer to null. After slow and fast meet, move one pointer to head and advance both one step at a time. Time is O(n), space is O(1).
Q. Find the next greater number with the same set of digits
asked 2xmediumStringsTechnical2017-2020
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 a pair with a given sum in a Balanced Binary Search Tree
asked 2xmediumTreesTechnical2017
Ans. Use two BST iterators, one giving the next smallest value by inorder traversal and one giving the next largest by reverse inorder traversal. Compare their sum with the target, advance the left iterator if too small, otherwise advance the right iterator. Stop when iterators meet. Time is O(n), space is O(log n).
Q. Multiply two numbers using a minimum number of addition operations.
asked 2xmediumMathOnline test2015
Ans. Add the larger absolute number to the result as many times as the smaller absolute number. This minimises additions for simple repeated addition, giving min(abs(a), abs(b)) additions. Handle the sign separately using XOR of negativity, work with absolute values, then apply the sign to the final result.
Q. Search for a given number in a 2D array sorted row-wise and column-wise
asked 2xmediumArraysTechnical2014
Ans. Start at the top-right element and eliminate one row or one column on each comparison. If the current value equals the target, return found; if it is larger, move left; if it is smaller, move down. This uses no extra data structure, takes O(rows + columns) time, and O(1) space.
Q. Explain multithreading concepts such as synchronization and the use of volatile.
asked 2xmediumOperating systemsTechnical2015
Ans. Multithreading runs multiple threads in one process, so shared data must be controlled to avoid races. Synchronization, such as locks or synchronized blocks, gives mutual exclusion and also ensures memory visibility. Volatile makes reads and writes visible across threads immediately, but it does not make compound actions like increment atomic.
Q. Design a data structure that supports insert, delete, search, and getRandom in O(1) time.
asked 2xmediumHashingTechnical2017
Ans. Use a dynamic array plus a hash map from value to its index in the array. Insert appends the value and stores its index, search checks the map, and getRandom picks a random array index. Delete swaps the target with the last element, updates that element’s index, then removes the last item.
Q. Given a boolean number in string form, write a program to output its 2's complement in the same string form.
asked 2xmediumBinaryOnline test2015
Ans. Scan the binary string from right to left, keep all bits up to and including the first 1 unchanged, then flip every bit to its left. If the string has no 1, return it unchanged. Use a character array or string builder for mutation. The time complexity is O(n).
Q. Given a binary matrix where each row consists of 1s followed by 0s, find the row with the maximum number of 1s.
asked 2xmediumArraysOnline test2015
Ans. Scan the rows while keeping the best count of 1s seen so far. For each row, check from that count onwards and move right while values are 1. Each move increases the best count and updates the answer row. This uses only indexes, returns the first maximum row, and runs in O(rows + columns).
Q. Find the number of pairs in an array whose sum is equal to a given value K. Numbers can be positive or negative.
asked 2xmediumArraysOnline test2015-2016
Ans. Use a hash map of frequencies and scan the array once. For each number x, add the current frequency of K minus x to the answer, then increment the frequency of x. This counts duplicate values correctly and works for negative numbers. The time complexity is O(n) and space is O(n).
Q. How would you determine whether a coin is biased? Does the degree of bias affect the number of experiments required?
asked 2xmediumProbabilityTechnical2014-2019
Ans. Flip the coin many times and record heads. Under a fair coin, heads follows a binomial distribution with probability 0.5. Compare the observed proportion with what is likely under that model, using a chosen significance level or confidence interval. Yes, smaller bias needs many more flips; larger bias is detected with fewer experiments.
Q. Design a garbage collector in C.
asked 2xhardMemory managementSystem design, Technical2015-2016
Ans. Use a conservative mark-and-sweep collector with a small allocation header before each block storing size, mark bit and next pointer. Keep all allocations in a linked list, scan stack, globals and registers for values that look like heap pointers, mark reachable blocks, then sweep the list and free unmarked blocks. Marking is linear in reachable memory, sweeping linear in allocations.
Q. 100 prisoners with red and black hats puzzle
asked 2xhardLogical reasoningTechnical2019-2020
Ans. Use parity. The last prisoner counts the red hats he can see and says “red” if the count is odd, “black” if even. He may die, but he gives everyone else the parity. Each next prisoner compares the announced parity with the hats ahead and previous answers, so can deduce his own hat. Thus 99 are guaranteed saved.
Q. Clone a linked list with next and random pointers
asked 2xhardLinked listsTechnical2014-2015
Ans. Create a new node for each original node and use a hash map from original node to cloned node. First pass copies all nodes and stores the mapping. Second pass sets each clone’s next and random using the map. This runs in O(n) time and uses O(n) extra space.
Q. Difference between TCP and UDP
asked 2xeasyNetworkingManagerial, Technical2017-2023
Ans. TCP is connection-oriented and reliable, while UDP is connectionless and faster but does not guarantee delivery. TCP orders packets, retransmits lost data, and provides flow and congestion control. UDP sends datagrams with minimal overhead, so it is useful for real-time traffic like video calls, gaming, DNS, or streaming where some loss is acceptable.
Q. Detect a loop in a linked list.
asked 2xeasyLinked listsTechnical2020-2021
Ans. Use Floyd’s cycle detection with two pointers, slow and fast, starting at the head. Move slow one node at a time and fast two nodes at a time. If they ever meet, there is a loop. If fast reaches null, there is no loop. This runs in O(n) time and O(1) space.
Q. Explain the memory layout in C++
asked 2xeasyOOPTechnical2015-2020
Ans. C++ program memory is commonly divided into code, static data, heap and stack areas. Code stores instructions, static data stores globals and static variables, including zero-initialised data. The stack holds function calls and local automatic variables. The heap holds dynamically allocated objects. The key detail is lifetime: stack objects end automatically, heap objects must be managed.
Q. Explain virtual functions in C++.
asked 2xeasyOOPTechnical2020
Ans. Virtual functions in C++ are member functions declared with virtual so calls are resolved at runtime based on the actual object type, not the pointer or reference type. They enable polymorphism, letting derived classes override base behaviour. A common important rule is to make base class destructors virtual when deleting derived objects through base pointers.
Q. Explain the volatile keyword in C.
asked 2xeasyCTechnical2015-2020
Ans. volatile tells the C compiler that an object’s value may change in ways it cannot see, so it must not optimise away or cache accesses to it. Each read or write must be performed as written. It is mainly used for memory-mapped hardware registers and signal-shared variables. It does not make operations atomic or thread-safe.
Q. Implement a queue using two stacks.
asked 2xeasyStackTechnical2017
Ans. Use two stacks, one for incoming elements and one for outgoing elements. Enqueue pushes onto the incoming stack. Dequeue pops from the outgoing stack; if it is empty, move all elements from incoming to outgoing first. This reverses order correctly. Each operation is amortised O(1), with O(n) extra space.
Q. Print a given matrix in spiral form
asked 2xeasyArraysManagerial, Online test2019-2021
Ans. Print the matrix by maintaining four boundaries: top, bottom, left and right. Traverse the top row, right column, bottom row and left column in order, shrinking the corresponding boundary after each pass. Continue while top is at most bottom and left is at most right. This visits each element once, so time is O(mn).
Q. What is a Binary Search Tree (BST)?
asked 2xeasyTreesTechnical2014-2021
Ans. A Binary Search Tree is a binary tree where each node has at most two children, and values in the left subtree are smaller than the node while values in the right subtree are larger. This ordering makes search, insert and delete efficient, usually O(log n) when balanced, but O(n) when skewed.
Q. Explain the Singleton design pattern
asked 2xeasyOOPTechnical2014-2020
Ans. The Singleton pattern ensures a class has exactly one instance and provides a global access point to it. It is usually implemented with a private constructor and a static method or property returning the instance. The key detail is thread safety, especially if the instance is created lazily in a multi-threaded program.
Q. Difference between semaphore and mutex
asked 2xeasyOperating systemsOnline test, Technical2017-2020
Ans. A mutex is a lock for exclusive access by one thread, while a semaphore is a counter that allows a fixed number of threads to access a resource. The key difference is ownership: the thread that locks a mutex should unlock it, but a semaphore can be signalled by another thread.
Q. Count the number of set bits in an integer
asked 2xeasyBit manipulationManagerial, Technical2015-2020
Ans. Use Brian Kernighan’s method: repeatedly replace n with n & (n - 1) and increment a counter until n becomes zero. Each operation removes the lowest set bit. The answer is the counter value. This uses no extra data structure, runs in O(number of set bits), and uses O(1) space.
Q. Find the second largest element in an array
asked 2xeasyArraysTechnical2014-2020
Ans. Scan the array once while keeping two variables: largest and second largest. For each element, update largest if it is bigger, shifting the old largest to second largest; otherwise update second largest if it lies between them. This uses constant extra space and runs in linear time. Handle duplicates based on whether “second largest” means distinct.
Q. Perform level order traversal of a binary tree
asked 2xeasyTreesTechnical2017-2023
Ans. Use breadth first search with a queue. Put the root in the queue, then repeatedly remove the front node, visit it, and add its left and right children if they exist. This visits nodes level by level from left to right. The time complexity is O(n), and the space complexity is O(w), where w is the maximum width.
Q. Convert a binary number to its decimal equivalent.
asked 2xeasyNumber systemOnline test, Technical2015-2016
Ans. Multiply each binary digit by 2 raised to its position value, starting from 0 on the right, then add the results. For example, in 1011, the values are 1×8, 0×4, 1×2 and 1×1. The total is 11, so 1011 in binary equals 11 in decimal.
Q. Check for balancing of parentheses in an expression
asked 2xeasyStackOnline test2014
Ans. Use a stack to check whether the parentheses are balanced. Scan the expression left to right, push every opening bracket, and for each closing bracket check it matches the stack top, then pop it. If a mismatch occurs or the stack is not empty at the end, it is unbalanced. Time complexity is O(n).
Q. Check if a pair with a given sum exists in an array.
asked 2xeasyArraysOnline test, Technical2014-2021
Ans. Use a hash set while scanning the array. For each value, check whether target minus value is already in the set; if it is, a valid pair exists. Otherwise, add the value and continue. This handles duplicates correctly and runs in O(n) time with O(n) extra space.
Q. Write a program to convert a binary number to decimal
asked 2xeasyBit manipulationTechnical2014-2019
Ans. Read the binary number as a string and scan it from left to right, maintaining an integer result initialised to zero. For each character, multiply the result by 2 and add the digit value, 0 or 1. This uses only one integer variable, runs in O(n) time, and uses O(1) extra space.
Q. Find the intersection point of two singly linked lists.
asked 2xeasyLinked listsTechnical2015
Ans. Use two pointers, one starting at each list head, and advance both one node at a time. When a pointer reaches the end, redirect it to the other list’s head. If the lists intersect, the pointers meet at the shared node; otherwise both become null. This takes O(m+n) time and O(1) space.
Q. Search an element in a row-wise and column-wise sorted matrix.
asked 2xeasyMatricesTechnical2015-2019
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 an array of size n with elements from {1,2,3,4}, find the minimum number of changes required so that no two adjacent elements are the same
asked 2xeasyArraysOnline test2017
Ans. The minimum number of changes is the sum of floor(length / 2) over every maximal run of equal adjacent values. Scan the array, count each consecutive block of the same number, and add half its length rounded down. This works because one change can break two equal adjacencies. Time complexity is O(n).
Q. Gold bar puzzle
asked 1xmediumLogical reasoningTechnical2016
Ans. Cut the seven-unit bar into pieces of 1, 2, and 4 units using two cuts. Pay one unit on day one, swap it for the 2-unit piece on day two, add the 1-unit piece on day three, swap both for the 4-unit piece on day four, then combine pieces to make five, six, and seven.
Q. Design a chess game
asked 1xmediumObject designTechnical2014
Ans. Design it around a Game holding an 8 by 8 Board, two Players, move history, current turn, status, and Piece objects with type, colour and movement rules. The key detail is separating legal move generation from game flow, so validation handles check, checkmate, castling, en passant and promotion consistently before applying any move.
Q. Design a coffee machine
asked 1xmediumObject oriented designSystem design2021
Ans. Design it as a state-driven machine with modules for payment, selection, inventory, brewing, dispensing and cleaning. The key detail is explicit state management, such as idle, paid, brewing, dispensing, error and maintenance, so failures like low water, empty beans, jammed cup or cancelled payment are handled safely and predictably.
Q. Torch and Bridge puzzle
asked 1xmediumLogical reasoningManagerial2020
Ans. Send the two fastest together first: 1 and 2 cross, 1 returns. Send the two slowest together: 5 and 10 cross, 2 returns. Then 1 and 2 cross again. Total time is 2 + 1 + 10 + 2 + 2 = 17 minutes. This minimises costly return trips.
Q. Camel and Banana Puzzle.
asked 1xmediumLogical reasoningTechnical2021
Ans. The maximum is 533⅓ bananas. Move in stages, reducing shuttle cost when stock drops below each 1000-banana load. With 3000 bananas, transport costs 5 bananas per kilometre until 2000 remain, so go 200 km. Then cost is 3 per kilometre until 1000 remain, so go 333⅓ km. The final 466⅔ km costs 466⅔ bananas.
Q. Clone an undirected graph
asked 1xmediumGraphsTechnical2020
Ans. Clone it with a graph traversal, creating one new node for each original node and copying all neighbour links. Use a hash map from original node to cloned node to avoid duplicate copies and handle cycles. BFS with a queue or DFS with recursion works. Time is O(V + E), space is O(V).
Q. Logical reasoning questions similar to CAT-level exams
asked 1xmediumLogical reasoningOnline test2013
Ans. Identify the exact question type first, such as arrangements, syllogisms, puzzles, blood relations, or assumptions. Translate words into simple symbols, tables, or diagrams. Fix definite information before handling possibilities. Eliminate options that violate any condition. For CAT-level reasoning, accuracy matters more than speed, so avoid assumptions not stated in the question.
Q. What test cases would you design if a system is running slow?
asked 1xmediumProblem solvingTechnical2016
Ans. Pick a real incident where slowness had business impact, such as checkout, search, or login. A strong answer covers baseline performance, load and stress tests, database and API latency checks, browser or device differences, network conditions, and regression tests. Emphasise prioritisation, evidence from metrics, and how you isolated the bottleneck.
Q. Describe how you would handle a situation where your manager pressures you to complete work quickly but you do not understand the task.
asked 1xmediumConflict resolutionHR2015
Ans. Pick a situation where unclear requirements created delivery risk. Emphasise that you stayed calm, asked focused questions, confirmed priorities and deadlines, and agreed a realistic next step. Interviewers listen for ownership, communication, and judgement under pressure, not passive waiting or rushing ahead and producing the wrong work.
Q. Given a matrix of platforms (iOS, Windows, Android) vs features (camera, music, internet, voice, locking), how would you plan testing and fill yes/no compatibility within one day before product launch?
asked 1xmediumProblem solvingManagerial2016
Ans. A strong answer should describe a time-critical compatibility triage. Pick the highest-risk platform and feature combinations first, then use existing specs, release notes, devices, simulators, and owners to confirm yes/no. Emphasise assumptions, evidence, defect escalation, and clear reporting. Interviewers listen for prioritisation, speed, risk judgement, and communication under launch pressure.
Showing 60 of 1,258 questions. Ranked by how often the same question came back across interviews.