Q. What is the difference between a process and a thread?
asked 7xeasyOperating systemsHR, Technical2019-2021
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. Implement Merge Sort algorithm.
asked 3xmediumSortingTechnical2019-2021
Ans. Merge sort is a divide and conquer sorting algorithm that splits the array into halves, sorts each half recursively, then merges the sorted halves. The key step is merging by comparing the smallest remaining elements. It runs in O(n log n) time and usually needs O(n) extra space.
Q. Print the top view of a binary tree
asked 3xmediumTreesOnline test, Technical2021-2023
Ans. Use level order traversal with a horizontal distance for each node, taking the first node seen at every distance. Store nodes in a queue with their distance, put the first value for each distance in an ordered map, then print map values from left to right. Time is O(n log n), or O(n) with hashing plus min and max distance.
Q. Print the left view of a binary tree
asked 3xmediumTreesOnline test, Technical2020-2021
Ans. Print the first node visible at each depth when the tree is viewed from the left. Do a level order traversal using a queue, and for each level print the first node removed from the queue. This visits every node once, so the time complexity is O(n), with O(w) space for the queue.
Q. Explain the Producer-Consumer problem.
asked 3xmediumOperating systemsTechnical2016-2018
Ans. Use a bounded blocking queue protected by a mutex, with two condition variables or semaphores for not full and not empty. Producers wait when the buffer is full, lock, enqueue an item, unlock, and signal consumers. Consumers wait when empty, lock, dequeue, unlock, and signal producers. Each produce or consume operation is O(1).
Q. Detect and remove a loop in a linked list
asked 3xmediumLinked listsTechnical2014-2022
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. Convert a given binary tree into a sum tree.
asked 3xmediumTreesOnline test, Technical2017-2020
Ans. Convert it using postorder traversal: first convert the left and right subtrees, then set the current node’s value to the sum of their original subtree values. The key detail is to return the original sum of each subtree to the parent. This takes O(n) time and O(h) recursion space.
Q. Find the closest leaf to a given node in a binary tree
asked 3xmediumTreesOnline test2017-2019
Ans. Use BFS from the given node, treating the binary tree as an undirected graph. First build parent pointers with a traversal, then start from the target and visit left child, right child, and parent. The first node reached that is a leaf in the original tree is the closest leaf. Time and space are O(n).
Q. Explain the KMP (Knuth-Morris-Pratt) string matching algorithm.
asked 3xmediumStringsTechnical2020-2021
Ans. KMP finds all occurrences of a pattern in a text in linear time by avoiding repeated comparisons after a mismatch. It first builds an LPS table, which stores the longest proper prefix that is also a suffix for each pattern prefix. During matching, it uses this table to shift the pattern without moving the text pointer backwards.
Q. Implement a queue using two stacks
asked 3xeasyStacks queuesTechnical2019-2020
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. What is the difference between TCP and UDP?
asked 3xeasyNetworkingTechnical2017-2019
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. Perform level order traversal of a binary tree
asked 3xeasyTreesOnline test, Technical2017-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. Find the largest prime factor of a given number.
asked 3xeasyMathOnline test2021
Ans. Divide the number by each prime factor found, keeping the latest factor as the largest. First remove all factors of 2, then test odd divisors from 3 up to the square root of the remaining number. If the remaining value is greater than 1, it is the largest prime factor. Time is O(sqrt n), space is O(1).
Q. Check whether a given number is an Armstrong Number
asked 3xeasyMathOnline test2020-2021
Ans. To check whether a number is an Armstrong number, count its digits, sum each digit raised to that count, and compare the sum with the original number. For example, 153 is valid because 1³ + 5³ + 3³ = 153. Process digits using division and modulo. Time complexity is O(d), space is O(1).
Q. What is the difference between SQL and NoSQL databases?
asked 3xeasyDBMSTechnical2019-2023
Ans. SQL databases store structured data in tables with fixed schemas and use SQL for relational queries. NoSQL databases use more flexible models such as documents, key value pairs, columns, or graphs. The key difference is that SQL favours strong consistency and complex joins, while NoSQL often favours flexibility, scale, and high availability.
Q. Difference between method overriding and method overloading
asked 3xeasyOOPTechnical2015-2021
Ans. Method overloading means defining multiple methods with the same name but different parameter lists in the same class, while method overriding means a subclass provides its own implementation of a method already defined in its parent class. Overloading is resolved at compile time, whereas overriding is resolved at runtime using dynamic dispatch.
Q. Explain CPU scheduling algorithms.
asked 2xmediumOperating systemsTechnical2015-2016
Ans. CPU scheduling algorithms decide which ready process gets the CPU next. Common algorithms include First Come First Served, Shortest Job First, Round Robin, Priority Scheduling and Multilevel Queue. The key trade-off is between throughput, response time, waiting time and fairness, with pre-emptive algorithms allowing the OS to interrupt a running process.
Q. Implement your own sizeof operator in C.
asked 2xmediumCTechnical2016-2019
Ans. Implement it as a macro using pointer arithmetic on an object’s address: take the address, add one element, cast both addresses to char pointers, then subtract them. The difference is the object size in bytes because char is one byte. This emulates sizeof for objects, but not perfectly for all type expressions.
Q. Convert a given binary tree to a sum tree
asked 2xmediumTreesOnline test2017-2020
Ans. Use postorder traversal and update each node after processing its children. For every node, recursively get the sum of the original left and right subtrees, store the node’s old value, set the node’s value to left sum plus right sum, and return that plus the old value. Time is O(n), stack space is O(h).
Q. Explain the memory layout of a C program.
asked 2xmediumMemory managementTechnical2016-2017
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 different CPU scheduling algorithms
asked 2xmediumOperating systemsTechnical2014-2016
Ans. CPU scheduling algorithms decide which ready process runs next. Common ones are First Come First Served, Shortest Job First, Priority Scheduling, Round Robin, and Multilevel Queue. The key trade-off is between fairness, response time, throughput, and starvation. Preemptive algorithms can interrupt running processes, while non-preemptive ones wait until completion or blocking.
Q. Find the longest increasing subsequence in an array.
asked 2xmediumDynamic programmingTechnical2020-2021
Ans. Use a patience sorting approach: maintain an array tails, where tails[i] is the smallest possible tail value of an increasing subsequence of length i + 1. For each number, binary search its position in tails and replace or append it. The length of tails is the LIS length. Time complexity is O(n log n).
Q. Find the Longest Palindromic Substring in a given string.
asked 2xmediumStringsTechnical2019-2021
Ans. Use expand around centres: for each index, expand once for an odd-length palindrome and once between indices for an even-length palindrome, tracking the best start and length. The key detail is handling both centre types. This uses only a few variables, runs in O(n squared) time, and uses O(1) extra space.
Q. Remove all keys from a BST that lie outside a given range
asked 2xmediumTreesOnline test2020
Ans. Trim the BST recursively by using its ordering property. If a node’s key is less than the lower bound, discard its left subtree and return the trimmed right subtree. If it is greater than the upper bound, return the trimmed left subtree. Otherwise, trim both children. This takes O(n) time and O(h) recursion space.
Q. Find the Lowest Common Ancestor (LCA) of two nodes in a tree.
asked 2xmediumTreesTechnical2024
Ans. Find it with a DFS from the root: if the current node is one target, return it; otherwise search its children and return the node where both targets are found in different branches. For a binary tree, this is recursive over left and right subtrees. Time is O(n), space is O(h).
Q. Find the shortest path in a binary matrix where 1 represents a path and 0 represents a blockage.
asked 2xmediumGraphsTechnical2018-2019
Ans. Use breadth-first search from the start cell, because every valid move has equal cost. Push reachable 1 cells into a queue with their distance, mark them visited, and stop when the target is dequeued. Check bounds and blockages for each neighbour. Time is O(rows × columns), space is O(rows × columns).
Q. Given a binary tree, replace the value of each node with the sum of values of all nodes in its subtree excluding the node itself
asked 2xmediumTreesOnline test2020
Ans. Use a postorder DFS and for each node first compute the total sum of its left and right subtrees, then replace the node’s value with that sum. Return the original node value plus the left and right subtree totals to its parent. This takes O(n) time and O(h) recursion stack space.
Q. Convert a binary tree into a Sum Tree where each node contains the sum of the values of its left and right subtrees in the original tree.
asked 2xmediumTreesOnline test2020
Ans. Use a postorder traversal and replace each node with the sum returned by its left and right subtrees. For each node, first convert children, store the node’s original value, set its value to left sum plus right sum, then return original value plus that new value. Time is O(n), stack space is O(h).
Q. Find the sum of cousins of a given node in a Binary Tree.
asked 2xhardTreesOnline test2020
Ans. Use level order traversal and sum all nodes at the target node’s depth whose parent is not the target’s parent. Store each queued node with its parent, find the target’s level and parent, then process only that level. The root has sum 0. Time is O(n), space is O(w).
Q. Burst Balloons (maximize coins by bursting balloons in optimal order)
asked 2xhardDynamic programmingOnline test2023
Ans. Use interval dynamic programming, treating each balloon as the last one burst in a subarray. Add virtual balloons of value 1 at both ends, then compute dp[left][right] as the best coins from bursting between them. Try every middle as the last burst. This uses a 2D table, with O(n³) time and O(n²) space.
Q. Fill numbers from 1 to 8 in 8 boxes such that no two consecutive numbers are adjacent horizontally, vertically, or diagonally.
asked 2xhardLogical reasoningHR2015-2016
Ans. Assuming the usual 2-4-2 box layout, one answer is top row 3,5; middle row 7,1,8,2; bottom row 4,6. The two middle boxes touch almost everything, so put endpoints 1 and 8 there. Then place each next number only in a non-touching box, giving the chain 1 to 8 as shown.
Q. Reverse a linked list.
asked 2xeasyLinked listsTechnical2020-2021
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 2xeasyLinked listsTechnical2020
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. What is a virtual function in C++?
asked 2xeasyOOPTechnical2016-2020
Ans. A virtual function in C++ is a member function declared with virtual so calls are resolved at runtime based on the actual object type. This enables polymorphism: a base class pointer or reference can call an overridden derived class method. Destructors should often be virtual in polymorphic base classes.
Q. Explain the layers of the OSI model
asked 2xeasyNetworkingHR, Technical2019-2020
Ans. The OSI model has seven layers: physical, data link, network, transport, session, presentation and application. They describe how data moves from raw bits on a medium, through framing, routing and reliable delivery, up to user-facing protocols. The key idea is separation of concerns, so each layer provides services to the one above.
Q. Implement a stack using a linked list
asked 2xeasyLinked listsTechnical2017-2021
Ans. Use a singly linked list and treat the head node as the top of the stack. To push, create a new node and link it before the current head. To pop, remove the head and return its value. Peek reads the head value. Push, pop and peek are O(1); space is O(n).
Q. Print the right view of a binary tree
asked 2xeasyTreesOnline test2021
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. What is thrashing in operating systems?
asked 2xeasyOperating systemsTechnical2020-2021
Ans. Thrashing is a state where an operating system spends most of its time swapping pages between memory and disk instead of executing processes. It usually happens when there is not enough physical memory for the active working sets, causing constant page faults, very low CPU utilisation, and poor overall performance.
Q. What is a kernel in an operating system?
asked 2xeasyOperating systemsTechnical2019
Ans. A kernel is the core part of an operating system that manages the computer’s hardware and provides essential services to software. It controls CPU scheduling, memory, devices, file access, and system calls. The key point is that it acts as the protected bridge between user programs and the hardware.
Q. Differentiate between mutex and semaphore
asked 2xeasyOperating systemsTechnical2014-2018
Ans. A mutex provides exclusive access to one shared resource, while a semaphore controls access to a limited number of resource instances. A mutex is locked and unlocked by the same thread, giving ownership. A semaphore is usually a counter, and any thread may signal it, making it useful for coordination as well as resource limiting.
Q. What is Inter Process Communication (IPC)?
asked 2xeasyOperating systemsTechnical2019-2021
Ans. Inter Process Communication is the set of operating system mechanisms that let separate processes exchange data and coordinate their actions. Common forms include pipes, message queues, shared memory, sockets and signals. The key issue is safe synchronisation, especially with shared memory, to avoid races, corruption and deadlocks.
Q. How do threads communicate with each other?
asked 2xeasyOperating systemsTechnical2019-2021
Ans. Threads usually communicate by sharing memory, such as common objects, variables, buffers or queues, within the same process. The key detail is that access must be synchronised using locks, mutexes, semaphores, condition variables or atomic operations, otherwise race conditions, lost updates and visibility problems can occur. Message queues are often used for safer coordination.
Q. What is the difference between hashmap and map?
asked 2xeasyData structuresTechnical2019-2021
Ans. A Map is the general key value abstraction, while a HashMap is a specific implementation that uses hashing. In Java, Map is an interface and HashMap is one class that implements it. The important practical detail is that HashMap gives average constant time lookup, insert and delete, but does not keep keys sorted.
Q. Explain the difference between semaphore and mutex.
asked 2xeasyOperating systemsTechnical2019
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. What is the difference between Structure and Class?
asked 2xeasyOOPTechnical2019-2022
Ans. In C++, a structure and a class are almost the same, but struct members are public by default, while class members are private by default. Structs are usually used for simple data grouping, while classes are usually used when data and behaviour are encapsulated together with controlled access.
Q. Find the missing number in an arithmetic progression
asked 2xeasyArraysOnline test2021
Ans. Use binary search to find the first position where the actual value differs from the expected arithmetic progression value. Compute the common difference from the first and last elements and the expected length. At index i, expected is first plus i times difference. The search takes O(log n) time and O(1) space.
Q. What is polymorphism in object-oriented programming?
asked 2xeasyOOPTechnical2018-2020
Ans. Polymorphism is the ability to treat different object types through the same interface while each type provides its own behaviour. For example, different shapes can all have an area method, but each calculates it differently. The key benefit is writing flexible code that depends on common behaviour rather than specific concrete classes.
Q. Explain the OSI model and the function of each layer.
asked 2xeasyNetworkingTechnical2019
Ans. The OSI model is a seven-layer framework for network communication: physical sends bits, data link frames local traffic, network routes packets, transport provides end-to-end delivery, session manages connections, presentation formats and encrypts data, and application supports user-facing protocols. The key idea is separation of responsibilities, making networks easier to design, debug, and standardise.
Q. Explain the Singleton Design Pattern and how it is implemented.
asked 2xeasyDesign patternsTechnical2014-2016
Ans. The Singleton pattern ensures a class has exactly one instance and provides a global access point to it. It is usually implemented by making the constructor private, storing a static instance inside the class, and exposing a static method or property to return it. In multithreaded code, creation must be thread safe.
Q. Minimum cut puzzle.
asked 1xmediumLogical reasoningTechnical2017
Ans. Two cuts are enough. Cut the seven-unit bar into pieces of 1, 2 and 4 units. Then use binary payment: day 1 give 1, day 2 swap for 2, day 3 add 1, day 4 swap for 4, day 5 add 1, day 6 add 2, day 7 add 1.
Q. Torch and bridge puzzle.
asked 1xmediumLogical reasoningTechnical2017
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. Design an ATM security system
asked 1xmediumSecurityTechnical2021
Ans. Design it as layered security: card and PIN authentication, encrypted communication to the bank, transaction limits, fraud scoring, tamper detection, cameras, alarms, and audit logging. The most important detail is that the ATM must never trust local state; every sensitive decision should be authorised by the bank backend over a secure, authenticated channel.
Q. Find the next number in a given sequence.
asked 1xmediumLogical reasoningHR2018
Ans. Look for the simplest consistent pattern: differences, ratios, alternating terms, squares, cubes, primes, or repeated operations. Check whether every term fits, not just the last two. If needed, split the sequence into odd and even positions. Once the rule is consistent, apply it once to get the next number.
Q. Design an LRU (Least Recently Used) cache.
asked 1xmediumCache designTechnical2025
Ans. Use a hash map plus a doubly linked list to implement an LRU cache. The map gives O(1) access from key to node, and the list keeps usage order. On get or put, move the node to the front. When capacity is exceeded, remove the tail in O(1).
Q. Discuss how you would design a smart city.
asked 1xmediumHigh level designTechnical2017
Ans. I would design a smart city as a secure, data-driven platform connecting transport, energy, water, waste, safety and citizen services through IoT sensors, edge processing and central analytics. The most important detail is governance: clear data ownership, privacy controls, open standards and resilient infrastructure so services can interoperate, scale and fail safely.
Q. Estimate the volume of the room you are sitting in.
asked 1xmediumEstimationHR2018
Ans. Estimate length, width and height, then multiply them. For example, if the room looks about 4 metres long, 3 metres wide and 2.5 metres high, the volume is 4 × 3 × 2.5 = 30 cubic metres. State assumptions clearly and round to sensible numbers.
Q. Explain and solve the Monty Hall probability problem
asked 1xmediumProbabilityTechnical2020
Ans. You should switch: it gives a 2/3 chance of winning, while staying gives 1/3. Initially your chosen door has 1/3 chance, and the other two together have 2/3. Monty always opens a losing door among the others, so that 2/3 probability transfers to the remaining unopened door. Method: track probabilities before and after the revealed information.
Q. What new applications can you envision for machine learning in mobile security?
asked 1xmediumProblem solvingTechnical2018
Ans. Choose a concrete mobile threat area, such as fraud, malware, phishing, or account takeover, and propose practical ML use cases like behavioural biometrics, on-device anomaly detection, app reputation scoring, or adaptive risk checks. Emphasise privacy, low latency, false positives, and adversarial attacks. Interviewers listen for creativity grounded in deployable security trade-offs.
Q. What will you do if you are given work outside your primary domain?
asked 1xeasyAdaptabilityHR2017
Ans. Pick a real example where you accepted unfamiliar work, clarified expectations, learned quickly, and delivered without neglecting core responsibilities. Emphasise adaptability, ownership, communication, and knowing when to ask for help. Interviewers listen for a positive attitude, sensible prioritisation, collaboration with experts, and evidence that you can stretch beyond your comfort zone.
Q. Effect of smartphones on human interaction
asked 1xunknownCommunicationGroup discussion2016
Ans. A strong answer should pick a balanced, real situation where smartphones helped connection but also reduced attention, such as teamwork, family time, or customer service. Emphasise awareness, boundaries, and practical habits like active listening or phone-free moments. Interviewers listen for judgement, empathy, communication skills, and avoidance of extreme claims.
Showing 60 of 1,268 questions. Ranked by how often the same question came back across interviews.