Q. How can you measure exactly 45 minutes using two identical wires?
asked 2xmediumLogical reasoningTechnical2021
Ans. Light wire A at both ends and wire B at one end. Wire A finishes in 30 minutes. At that instant, light the other end of wire B. Wire B has 30 minutes of burn time left from one end, so burning it from both ends uses that remainder in 15 minutes. Total: 45 minutes.
Q. Difference between function overloading and function overriding.
asked 2xeasyOOPTechnical2019-2023
Ans. Function overloading means defining multiple functions with the same name but different parameter lists, while function overriding means a subclass provides its own implementation of a method already defined in its superclass. Overloading is resolved at compile time in many languages; overriding is resolved at run time using dynamic dispatch.
Q. Design a 5-bit counter.
asked 1xmediumOOPTechnical2015
Ans. A 5-bit counter is a modulo-32 binary counter built from five flip-flops, producing states 00000 through 11111 and then wrapping to 00000. In a synchronous design, the least significant bit toggles every clock, and each higher bit toggles only when all lower bits are 1.
Q. Explain object slicing in C++.
asked 1xmediumOOPTechnical2016
Ans. Object slicing in C++ happens when a derived object is copied into a base class object by value, so the derived-specific part is discarded. The result contains only the base subobject, losing derived data and behaviour. Avoid it by using references, pointers, or smart pointers when working polymorphically.
Q. How does dynamic casting work?
asked 1xmediumOOPTechnical2021
Ans. Dynamic casting performs a runtime-checked conversion within an inheritance hierarchy, most commonly using C++ dynamic_cast. It uses RTTI, so the base class must be polymorphic, usually with at least one virtual function. If a pointer cast is invalid it returns null; if a reference cast is invalid it throws std::bad_cast.
Q. Explain shortest path algorithms
asked 1xmediumGraphsTechnical2014
Ans. Shortest path algorithms find the minimum-cost route between vertices in a graph. Use BFS for unweighted graphs, Dijkstra’s algorithm with a priority queue for non-negative edge weights, Bellman-Ford when negative weights may exist, and Floyd-Warshall for all-pairs shortest paths. The key detail is matching the algorithm to edge weights and query type.
Q. Detect a cycle in a directed graph.
asked 1xmediumGraphsTechnical2019
Ans. Use DFS with a recursion stack to detect a cycle in a directed graph. Mark each node as unvisited, visiting, or visited. During DFS, if you reach a node marked visiting, there is a cycle. If DFS finishes, mark it visited. This takes O(V + E) time and O(V) space.
Q. Implement a queue using two stacks.
asked 1xmediumStacks queuesTechnical2021
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. Explain Support Vector Machines (SVM)
asked 1xmediumMachine learningTechnical2014
Ans. Support Vector Machines are supervised learning models that classify data by finding the hyperplane that best separates classes with the largest margin. The key idea is that only the closest training points, called support vectors, determine the boundary. With kernels, SVMs can also handle non-linear separation by mapping data into higher-dimensional spaces.
Q. Explain cache memory and its working.
asked 1xmediumComputer architectureTechnical2017
Ans. Cache memory is a small, very fast memory between the CPU and main memory that stores recently or frequently used data and instructions. When the CPU needs data, it checks the cache first. A cache hit is fast; a cache miss fetches from RAM and usually stores a copy for future access.
Q. Explain the concept of virtual memory.
asked 1xmediumOperating systemsTechnical2017
Ans. Virtual memory is an operating system technique that gives each process the illusion of a large, private, continuous memory space. It maps virtual addresses to physical RAM using page tables. The key detail is paging: inactive pages can be kept on disk and loaded into RAM when needed, enabling isolation and efficient memory use.
Q. How to make a C++ object non-copyable?
asked 1xmediumOOPTechnical2019
Ans. Declare the copy constructor and copy assignment operator as deleted. This prevents copying at compile time and gives a clear error if code tries to copy the object. In older C++, make them private and do not define them. Decide separately whether move construction and move assignment should be allowed.
Q. Implement your own Vector class in C++
asked 1xmediumOOPTechnical2021
Ans. Implement it as a dynamic array storing a pointer to heap memory, current size, and capacity. Support indexing, push_back, pop_back, reserve, resize, copy, move, and destruction. When full, allocate a larger array, usually double capacity, move elements, then free old storage. Indexing is O(1), push_back is amortised O(1).
Q. Check whether a binary tree is balanced
asked 1xmediumTreesTechnical2014
Ans. Use a postorder DFS that computes subtree heights while checking balance. For each node, get left and right heights; if either subtree is unbalanced or their difference is more than one, return a failure marker. Otherwise return height plus one. This visits each node once, so time is O(n).
Q. Explain template specialization in C++.
asked 1xmediumTemplatesTechnical2021
Ans. Template specialization in C++ lets you provide a custom implementation of a template for a specific type or set of types. The compiler uses the specialised version when the template arguments match. Class templates can be fully or partially specialised, while function templates can be fully specialised, with overloading often used instead.
Q. Check whether a given graph is bipartite
asked 1xmediumGraphsTechnical2021
Ans. Use BFS or DFS to colour each node with one of two colours, ensuring every edge connects nodes of different colours. Start from every unvisited node, since the graph may be disconnected. Store colours in an array or map. If a neighbour has the same colour, it is not bipartite. Time complexity is O(V + E).
Q. Explain minimum spanning tree algorithms
asked 1xmediumGraphsTechnical2014
Ans. Minimum spanning tree algorithms find a set of edges connecting all vertices with minimum total weight and no cycles. Kruskal sorts edges and uses union find to add safe edges. Prim grows from a start vertex using a priority queue. Typical time is O(E log E) for Kruskal and O(E log V) for Prim.
Q. What is a virtual table (vtable) in C++?
asked 1xmediumOOPTechnical2016
Ans. A virtual table, or vtable, is a compiler-generated table used to support runtime dispatch of virtual functions in C++. Each polymorphic object typically stores a hidden pointer to its class’s vtable. When a virtual function is called through a base pointer or reference, C++ uses it to call the correct overridden function.
Q. Find the Kth largest element in an array.
asked 1xmediumHeapTechnical2019
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. Swap the adjacent bits of a given number.
asked 1xmediumBit manipulationTechnical2023
Ans. Separate the number’s odd and even positioned bits with masks, shift them towards each other, then combine them. For a 32-bit integer, use 0xAAAAAAAA for odd-position bits and 0x55555555 for even-position bits. Shift odd bits right, even bits left, then OR them. Time complexity is O(1).
Q. Write your own iterator for a list class.
asked 1xmediumOOPTechnical2021
Ans. Create an iterator object that holds a reference to the list and the current node or index. It exposes methods like hasNext and next, where next returns the current value and advances the position. For a linked list it stores a node pointer. Each move is O(1), and full traversal is O(n).
Q. Create an OR gate using a 2:1 multiplexer.
asked 1xmediumLogical reasoningTechnical2023
Ans. Use one input, say A, as the select line of the 2:1 multiplexer. Connect input 0 to B and input 1 to logic 1. The output is then A'B + A, which simplifies to A + B, so the multiplexer behaves as an OR gate.
Q. Detect and remove a loop in a linked list.
asked 1xmediumLinked listsTechnical2014
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. Given a BST, find the kth largest element.
asked 1xmediumTreesTechnical2015
Ans. Find the kth largest element by doing a reverse in-order traversal: visit right subtree, then node, then left subtree, and count visited nodes. The kth visited node is the answer. Use recursion or an explicit stack. Time is O(h + k) on average, O(n) worst case, with O(h) space.
Q. Implement insert operation for a max heap.
asked 1xmediumHeapsTechnical2016
Ans. Insert by adding the new value at the end of the heap array, then restore the max heap property by bubbling it up. Compare it with its parent and swap while it is larger. Stop at the root or when the parent is larger. Time complexity is O(log n), with O(1) extra space.
Q. Check whether a linked list is a palindrome
asked 1xmediumLinked listsTechnical2024
Ans. Use two pointers to find the middle, reverse the second half of the linked list, then compare it node by node with the first half. The key detail is restoring the reversed half afterwards if the list must remain unchanged. This uses constant extra space and takes O(n) time.
Q. Design an Array class using features of C++.
asked 1xmediumOOPTechnical2019
Ans. Design it as a template class managing a contiguous dynamic buffer with size and capacity fields. Use RAII: allocate in the constructor, release in the destructor, and implement copy, move, assignment, and bounds checked access. Indexing is O(1), append is O(1) amortised if capacity grows geometrically.
Q. Explain the Scan Line (Sweep Line) algorithm
asked 1xmediumAlgorithmsTechnical2021
Ans. The Scan Line, or Sweep Line, algorithm processes geometric or interval problems by moving an imaginary line across sorted events and maintaining the objects currently intersecting that line. The key detail is the active set, often a balanced tree or heap, which lets you update and query efficiently, typically in O(n log n) time.
Q. Explain how printf works internally in C/C++.
asked 1xmediumC cppTechnical2017
Ans. printf is a variadic library function that parses the format string left to right and writes ordinary characters directly, while format specifiers tell it how to fetch and convert the next argument. Internally it uses va_list mechanisms, converts values to text, buffers output through stdio, and eventually writes to the target stream. Mismatched types cause undefined behaviour.
Q. Explain virtual functions and their behavior.
asked 1xmediumOOPTechnical2015
Ans. Virtual functions are member functions that are resolved at run time based on the actual object type, not the pointer or reference type used to access it. They enable polymorphism, so a base class pointer can call an overridden derived class method. In C++, declare them with virtual, and use a virtual destructor for polymorphic bases.
Q. Difference between deep copy and shallow copy.
asked 1xmediumOOPTechnical2019
Ans. A shallow copy creates a new outer object but reuses references to the same nested objects, while a deep copy recursively creates new copies of nested objects too. The key difference is aliasing: changing a shared nested object affects both the original and shallow copy, but not a proper deep copy.
Q. How do you validate that a graph has no cycle?
asked 1xmediumGraphsTechnical2017
Ans. Use depth first search to detect a cycle, and validate the graph as acyclic only if no back edge is found. For a directed graph, track nodes as unvisited, visiting and visited; reaching a visiting node means a cycle. For an undirected graph, ignore the edge back to the parent. Time complexity is O(V + E).
Q. How to dynamically allocate a 2D array in C++?
asked 1xmediumMemory managementTechnical2019
Ans. Use a vector of vectors, such as an outer vector holding rows and each inner vector holding columns. This is the usual safe C++ approach because memory is managed automatically. If contiguous storage matters, use one flat vector of size rows times columns and index it manually. Allocation is O(rows times columns).
Q. Explain stack management during function calls.
asked 1xmediumOperating systemsTechnical2015
Ans. Function calls are managed using a call stack, where each call creates a stack frame holding its parameters, local variables, return address and saved registers. When the function returns, its frame is popped and control resumes at the saved address. This last in, first out structure naturally supports nested and recursive calls.
Q. Search a given word in a 2D grid of characters.
asked 1xmediumMatrixTechnical2017
Ans. Use backtracking DFS from every cell that matches the first character, trying the next character in each allowed neighbouring direction. Keep a visited marker so the same cell is not reused in one path, then unmark on return. Time is O(rows × cols × 4^word length), or 8 directions if diagonals are allowed.
Q. Explain thrashing in the context of page faults.
asked 1xmediumOperating systemsTechnical2016
Ans. Thrashing is a state where a system spends most of its time handling page faults and swapping pages instead of executing useful work. It happens when processes do not have enough physical memory for their working sets, causing pages to be repeatedly evicted and reloaded, which severely reduces CPU utilisation and overall performance.
Q. Implement a Singleton class. Can it be inherited?
asked 1xmediumOOPTechnical2021
Ans. Implement it with a private constructor, a private static instance, and a public static access method that lazily or eagerly returns the same instance. Make creation thread safe, for example by using language-level static initialisation. It generally cannot be inherited if the constructor is private; allowing inheritance weakens the singleton guarantee.
Q. Perform BFS traversal of a graph using recursion.
asked 1xmediumGraphsTechnical2015
Ans. Use recursion around a queue: mark the start node visited, enqueue it, then recursively process the queue by dequeuing one node, visiting it, enqueuing all unvisited neighbours, and calling the function again. The recursion stops when the queue is empty. Time complexity is O(V + E), with O(V) extra space.
Q. Check whether a given binary tree is a BST or not.
asked 1xmediumTreesTechnical2019
Ans. Use a depth first traversal with valid lower and upper bounds for each node. A node is valid only if its value lies strictly between those bounds, then update the bounds for its left and right children. This checks the whole tree in O(n) time and O(h) recursion space.
Q. Find the number of days in a month using two dice.
asked 1xmediumLogical reasoningTechnical2017
Ans. Label the dice as calendar cubes. Put 0, 1, 2, 3, 4, 5 on one die and 0, 1, 2, 6, 7, 8 on the other, treating 6 upside down as 9. This lets you form 01 to 31, including repeated 11 and 22 because 1 and 2 are on both dice.
Q. What is a HashMap and how does it work internally?
asked 1xmediumData structuresTechnical2016
Ans. A HashMap is a key value data structure that uses hashing to store and find values quickly. Internally, it hashes the key to choose a bucket in an array. If multiple keys map to the same bucket, it resolves collisions, commonly with a linked list or tree, using equality checks to find the right entry.
Q. What is the size of an empty class in C++ and why?
asked 1xmediumOOPTechnical2019
Ans. An empty class in C++ has size 1 byte in most cases. The language requires every complete object to have a unique address, so even an object with no data members cannot have size zero. However, when used as a base class, empty base optimisation may allow it to occupy no extra space.
Q. Find the maximum sum path across two sorted arrays.
asked 1xmediumArraysTechnical2021
Ans. Use two pointers and keep running sums for both arrays between common values. When the same value is found in both arrays, add the larger running sum plus that common value to the answer, then reset both sums and continue. After traversal, add the larger remaining sum. Time is O(n + m), space is O(1).
Q. Operating System concepts questions (10 questions).
asked 1xmediumOperating systemsOnline test2016
Ans. The ten key OS concepts are processes, threads, scheduling, context switching, synchronisation, deadlocks, memory management, virtual memory, file systems and system calls. Focus on how the OS shares CPU, memory and I/O safely between programs, because most interview questions test trade-offs, resource control and concurrency correctness.
Q. Find the height and balance factor of a binary tree.
asked 1xmediumTreesTechnical2014
Ans. Compute height with a postorder DFS, and for each node compute balance factor as height of left subtree minus height of right subtree. Use recursion: get left height, get right height, set current height to one plus the larger value. This visits each node once, so time is O(n) and stack space is O(h).
Q. Check if a binary tree is a Binary Search Tree (BST).
asked 1xmediumTreesTechnical2014
Ans. Check it by recursively validating each node against an allowed value range. For a BST, every node in the left subtree must be less than the current node, and every node in the right subtree greater, with bounds carried down from ancestors. This takes O(n) time and O(h) recursion space.
Q. Design a 32x1 multiplexer using only 2x1 multiplexers.
asked 1xmediumDigital logicTechnical2019
Ans. Use a five-level binary tree of 2x1 multiplexers to build the 32x1 multiplexer. The first level uses 16 muxes to select from 32 inputs, then 8, 4, 2, and finally 1 mux. Use five select lines, one per level, giving 31 total 2x1 multiplexers.
Q. Design a bounding box solution for a cluster of points
asked 1xmediumGeometryTechnical2014
Ans. Scan all points once and keep the minimum and maximum x and y values; the bounding box is then bottom-left (minX, minY) and top-right (maxX, maxY). Store four variables, or six for 3D. This takes O(n) time, O(1) space, and handles negative coordinates naturally.
Q. Explain function overloading and name mangling in C++.
asked 1xmediumOOPTechnical2017
Ans. Function overloading lets C++ define multiple functions with the same name but different parameter lists, and name mangling is how the compiler encodes those signatures into unique linker symbols. Overload resolution happens at compile time. The key detail is that return type alone cannot overload a function, and mangling is compiler-specific.
Q. Validate whether a binary tree is a binary search tree
asked 1xmediumTreesTechnical2021
Ans. Validate it by traversing the tree with a valid value range for each node. Each node must be greater than its lower bound and less than its upper bound, then update the bounds for its children. Use recursion with the call stack. This visits each node once, so time is O(n) and space is O(h).
Q. Print numbers from -4 to -10 without using a semicolon.
asked 1xmediumCTechnical2021
Ans. Use a loop whose body is empty and put printf in the loop expression. In C, this works without any semicolon: int i = -4; while (i >= -10 && printf("%d ", i--)) {}. The condition prints the current value, then decrements it, stopping after -10.
Q. Find all nodes between two given nodes in a binary tree.
asked 1xmediumTreesManagerial2019
Ans. Find the lowest common ancestor of the two nodes, then collect the path from it to each node and join those paths, reversing one side as needed. Use DFS recursion with a list to store the current path. This works for a normal binary tree in O(n) time and O(h) auxiliary space, excluding output.
Q. Find the second largest element in a Binary Search Tree.
asked 1xmediumTreesTechnical2021
Ans. Find the second largest by walking to the rightmost node while keeping its parent. If the largest node has a left subtree, the answer is the maximum node in that left subtree; otherwise, it is the parent. This takes O(h) time and O(1) extra space.
Q. Quantitative, analytical, and logical reasoning questions (10 questions).
asked 1xmediumLogical reasoningOnline test2016
Ans. Use a structured process: identify what is being asked, list the given facts, convert words into equations, tables, diagrams, or sequences, then solve step by step. Eliminate impossible options in multiple choice questions. For logic puzzles, track conditions carefully and check consistency before choosing the final answer.
Q. What would you do if you feel your friend is getting favoritism from your manager?
asked 1xmediumConflict resolutionTechnical2019
Ans. Pick a situation where you stayed professional despite personal ties. Emphasise separating friendship from fairness, checking facts before judging, focusing on your own performance, and raising concerns privately with evidence if needed. Interviewers listen for maturity, discretion, lack of jealousy, and trust in fair process rather than gossip.
Q. Design an API to move contents of a buffer from one memory location to another, handling all edge cases.
asked 1xmediumApi designTechnical2021
Ans. Expose memmove as void *move(void *dest, const void *src, size_t len), returning dest after copying exactly len bytes. If len is zero, do nothing. If pointers are null with nonzero len, return an error or define it invalid. The key detail is overlap: copy forwards when dest is before src, backwards otherwise.
Q. In how many ways can the letters of the word 'CORPORATION' be arranged so that all vowels come together?
asked 1xmediumProbabilityTechnical2019
Ans. Treat all vowels as one block. The units are this vowel block plus C, R, P, R, T, N, so arrange 7 units with two R’s repeated: 7!/2!. Inside the vowel block, arrange O, O, O, A, I: 5!/3!. Total ways = 7!/2! × 5!/3! = 50,400.
Q. Design a library system without using a database supporting add, delete, prefix-based search, and author-based search.
asked 1xmediumLow level designTechnical2021
Ans. Use in-memory indexes: a hash map from book id to book, a trie on title for prefix search, and a hash map from author to a set of book ids. Add inserts into all three. Delete removes from all three using the id map. Prefix search is O(p + k), author search is O(k).
Q. Design an audio player that plays songs randomly without repetition until all songs are played, without using extra space.
asked 1xmediumDesignTechnical2019
Ans. Use the song array itself as the shuffle state, using an in-place Fisher-Yates approach. Keep an index for the next unplayed position, choose a random song from the remaining range, swap it into that position, and play it. When the index reaches the end, reset and reshuffle. Each play is O(1), with no extra song storage.
Q. Find the next number in the series: 3, 5, 8, 13, 22, ?
asked 1xeasyLogical reasoningHR2021
Ans. 39. Look at the differences between terms: 5 minus 3 is 2, 8 minus 5 is 3, 13 minus 8 is 5, and 22 minus 13 is 9. The increases between these differences are 1, 2, and 4, so next is 8. Thus next difference is 17, giving 39.
Showing 60 of 341 questions. Ranked by how often the same question came back across interviews.