Q. Rotate a linked list in groups of k.
asked 2xmediumLinked listsOnline test2019
Ans. Use pointer manipulation to process each k-sized block independently: find the block boundary, rotate the nodes inside that block, then connect the previous block’s tail to the block’s new head and its new tail to the next block. A dummy head simplifies edge cases. This uses O(n) time and O(1) extra space.
Q. Count the number of inversions in an array
asked 2xmediumArraysOnline test2019
Ans. Use a modified merge sort to count inversions in O(n log n) time. While merging two sorted halves, if an element from the right half is smaller than one from the left, it forms inversions with all remaining elements in the left half. Add that count, merge normally, and return the total.
Q. How would you optimize a recommendation system with O(n^3) time complexity to work efficiently on a large dataset?
asked 2xmediumOptimizationTechnical2019
Ans. Replace the cubic algorithm with a sparse, offline model such as matrix factorisation or item based collaborative filtering, then serve recommendations from precomputed top-k candidates. The key is to avoid comparing every user-item combination at request time. Use sparse matrices, approximate nearest neighbours, batching, and caching so online latency is near constant.
Q. Maximize profit by buying and selling a stock at most k times.
asked 2xhardDynamic programmingTechnical2019
Ans. Use dynamic programming with two arrays: buy[t] is the best profit after buying in transaction t, and sell[t] is the best profit after selling transaction t. For each price, update buy and sell for t from 1 to k. If k >= n/2, use unlimited-transactions greedy. Time is O(nk), space is O(k).
Q. Explain exception handling in Java.
asked 2xeasyOOPTechnical2019-2022
Ans. Exception handling in Java is a mechanism for dealing with runtime errors without abruptly stopping normal program flow. Risky code is placed in a try block, errors are handled in catch blocks, and cleanup goes in finally. Java has checked exceptions, which must be caught or declared, and unchecked exceptions.
Q. Which is the best sorting algorithm and why?
asked 2xeasySortingTechnical2019-2020
Ans. There is no single best sorting algorithm, because the choice depends on the data and constraints. In practice, Timsort is often best for general-purpose library sorting because it is stable, fast on real-world partially sorted data, and has O(n log n) worst-case time. Quicksort is fast on average but not always stable.
Q. Write code to generate the Fibonacci series.
asked 2xeasyRecursionTechnical2023
Ans. Generate the Fibonacci series by starting with 0 and 1, then repeatedly adding the previous two numbers to get the next term until the required count is reached. Store the values in an array or list if they must be returned. The time complexity is O(n), with O(n) space, or O(1) if printed directly.
Q. Explain Polymorphism in Object-Oriented Programming
asked 2xeasyOOPTechnical2019
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. Find the sum of all digits of a number repeatedly until the sum becomes a single digit.
asked 2xeasyMathOnline test2019
Ans. Use the digital root: if the number is 0, the answer is 0; otherwise the answer is 1 plus the remainder of number minus 1 divided by 9. This avoids repeated summing. No extra data structure is needed. The time complexity is O(1), compared with O(digits) per pass for simulation.
Q. Java OOPS fundamentals
asked 1xmediumOOPTechnical2014
Ans. Java OOP fundamentals are encapsulation, inheritance, polymorphism and abstraction. Encapsulation hides data behind methods, inheritance reuses and extends behaviour, polymorphism lets the same interface have different implementations, and abstraction exposes only essential details. In Java, these are implemented mainly using classes, objects, interfaces, abstract classes, access modifiers and method overriding.
Q. Design a vending machine system
asked 1xmediumObject designTechnical2024
Ans. Design it as a state machine with states like idle, selecting item, accepting payment, dispensing, returning change, and out of service. Core components are inventory, payment handling, pricing, change management, dispenser, and controller. The most important detail is making payment and inventory updates transactional so money is not taken unless dispensing succeeds.
Q. Detect a cycle in a linked list
asked 1xmediumLinked listsTechnical2016
Ans. Use Floyd’s tortoise and hare algorithm: keep two pointers, one moving one node at a time and the other moving two nodes at a time. If they ever meet, there is a cycle. If the fast pointer reaches null, there is no cycle. It uses constant extra space and runs in O(n) time.
Q. Explain memory management in C++
asked 1xmediumOOPTechnical2016
Ans. Memory management in C is mostly manual: the programmer decides when to allocate and free heap memory. Local variables usually live on the stack, global and static variables have static storage, and dynamic memory comes from the heap using malloc, calloc, realloc, and free. The key risk is freeing incorrectly or forgetting to free, causing bugs or leaks.
Q. Write SQL queries involving joins
asked 1xmediumSQLTechnical2021
Ans. Use joins by selecting columns from related tables and matching their keys in the join condition. For example, join customers to orders on customer id to return each order with its customer details. Use inner join for matching rows, left join to keep all rows from the left table, and filter with where.
Q. Explain how the C++ compiler works
asked 1xmediumCompiler designManagerial2021
Ans. A C++ compiler turns source code into an executable through preprocessing, parsing, semantic analysis, optimisation, code generation, assembly and linking. The key detail is that each source file is compiled as a separate translation unit, then the linker combines object files and libraries, resolving symbols such as functions and global variables.
Q. Perform merge sort on a linked list
asked 1xmediumLinked listsTechnical2021
Ans. Use merge sort by splitting the linked list into two halves with slow and fast pointers, recursively sorting each half, then merging the two sorted lists by relinking nodes. The key detail is to cut the list at the midpoint before recursion. It runs in O(n log n) time and O(log n) stack space.
Q. Write the Merge Sort algorithm/code
asked 1xmediumSortingTechnical2019
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. Explain the Huffman coding algorithm
asked 1xmediumAlgorithmsTechnical2016
Ans. Huffman coding builds an optimal prefix-free binary code by giving shorter codes to more frequent symbols. Count frequencies, put symbols in a min-heap, repeatedly remove the two least frequent nodes, merge them, and insert the parent. Label left and right edges 0 and 1. Building the tree takes O(n log n).
Q. Explain the types of schedules in DBMS
asked 1xmediumDBMSTechnical2021
Ans. DBMS schedules are mainly serial schedules and non-serial schedules. In a serial schedule, transactions run one after another, so consistency is simple but concurrency is low. In a non-serial schedule, operations are interleaved for better performance. The important requirement is serializability, meaning the result matches some valid serial order.
Q. Networking theory questions (descriptive)
asked 1xmediumNetworkingOnline test2014
Ans. Please send the specific networking theory question you want answered. I can then give a direct 40 to 60 word interview-style response, starting with the answer and adding the most important detail, such as protocol purpose, layer, packet flow, reliability, latency, congestion, DNS, TCP, UDP, HTTP, or routing.
Q. Reverse a linked list in groups of size k
asked 1xmediumLinked listsOnline test2019
Ans. Reverse each block of k nodes by rewiring next pointers, then connect the previous block’s tail to the new head of the reversed block. Use three pointers to reverse a block in place, and first check that k nodes remain if partial groups should stay unchanged. Time complexity is O(n), space complexity is O(1).
Q. Rotate a linked list in groups of size k.
asked 1xmediumLinked listsOnline test2019
Ans. Split the list into consecutive groups of k nodes, rotate each group in place, then connect the rotated group back to the previous and next parts. The key detail is to keep pointers to the group’s previous node, head, tail, and next node. This takes O(n) time and O(1) extra space.
Q. Generate all permutations of a given string.
asked 1xmediumBacktrackingTechnical2017
Ans. Use backtracking to build permutations one character at a time until the current string has the same length as the input. Keep a used boolean array to mark chosen characters, or swap characters in place. The key detail is duplicates: sort first and skip repeated unused choices. Time complexity is O(n! × n).
Q. Explain CPU scheduling in an Operating System
asked 1xmediumOperating systemsTechnical2024
Ans. CPU scheduling is the operating system’s method of choosing which ready process or thread gets the CPU next. It keeps the processor busy, improves responsiveness, and shares CPU time fairly. Common policies include First Come First Served, Shortest Job First, Priority, and Round Robin, each trading off throughput, waiting time, and fairness.
Q. Explain an algorithm to solve a Sudoku puzzle.
asked 1xmediumBacktrackingTechnical2015
Ans. Use backtracking: find an empty cell, try digits 1 to 9 that do not already appear in its row, column, or 3 by 3 box, place one, and recurse. If no digit works, undo and try the next. Keep row, column, and box sets for fast validity checks. Worst case is exponential.
Q. Design a student registration management system
asked 1xmediumApplication designSystem design2020
Ans. Design it as a web service with student, course, section, prerequisite, enrolment and payment modules backed by a relational database. The most important detail is enforcing capacity and clash rules atomically during enrolment, using transactions, row locking or optimistic concurrency, so two students cannot take the last seat at the same time.
Q. Explain database normalization and normal forms
asked 1xmediumDBMSTechnical2016
Ans. Database normalization is the process of organising relational tables to reduce duplication and avoid update, insert and delete anomalies. 1NF makes values atomic, 2NF removes partial dependency on a composite key, 3NF removes transitive dependency, and BCNF is stricter, requiring every determinant to be a candidate key.
Q. Heights and distances problems using trigonometry
asked 1xmediumLogical reasoningOnline test2016
Ans. Draw a clear right angled triangle from the situation. Mark the height, horizontal distance, and angle of elevation or depression. Use trigonometric ratios, usually tan θ = opposite/adjacent for height and distance. If two positions are given, form two equations and subtract or solve them together. Keep units consistent.
Q. Remove the nth node from the end of a linked list
asked 1xmediumLinked listsTechnical2019
Ans. Use two pointers with a dummy node before the head. Move the fast pointer n steps ahead, then move fast and slow together until fast reaches the end. The slow pointer then points before the node to remove, so bypass it. This handles deleting the head cleanly. Time is O(n), space is O(1).
Q. Basic logic-based aptitude questions (30 problems)
asked 1xmediumLogical reasoningOnline test2014
Ans. Break each problem into facts, conditions, and required conclusion. Translate words into simple symbols, tables, or diagrams where useful. Eliminate impossible options first, then test the remaining choices against every condition. For sequences, look for changes, positions, or alternating patterns. Work slowly enough to avoid assumptions not stated in the question.
Q. What is an object file and what does the linker do?
asked 1xmediumCompilerTechnical2016
Ans. An object file is the compiled output of a source file, containing machine code plus metadata such as symbols and relocation information. The linker combines object files and libraries into an executable or shared library, resolving references between them, assigning final addresses, and reporting errors for missing or duplicate symbols.
Q. Convert a binary tree into its mirror image in-place
asked 1xmediumTreesOnline test2016
Ans. Swap the left and right child of every node in the binary tree, modifying the existing nodes in-place. Do a depth-first traversal recursively, or use an explicit stack for iteration. At each node, swap its children, then process the children. Time complexity is O(n), and extra space is O(h) recursively.
Q. Find the distance between two nodes in a binary tree
asked 1xmediumTreesTechnical2021
Ans. Find the lowest common ancestor of the two nodes, then compute the distance from it to each node and add those distances. Equivalently, distance equals depth(a) plus depth(b) minus twice depth(LCA). Use a DFS to find the LCA and depths. Time complexity is O(n), with O(h) recursion space.
Q. Permutation and combination problems with probability
asked 1xmediumProbabilityOnline test2016
Ans. Count the total possible arrangements or selections, then count the favourable ones, and divide favourable by total. Use permutations when order matters and combinations when it does not. For probability, make sure each outcome is equally likely. Handle restrictions by fixing, excluding, or splitting cases, then add or multiply counts as appropriate.
Q. Draw and explain the typical memory layout of a program
asked 1xmediumOperating systemsTechnical2016
Ans. A typical process memory layout is: text/code, read-only data, initialised data, BSS, heap growing upward, then stack growing downward. The text segment holds instructions, data holds globals, BSS holds zero-initialised globals, the heap holds dynamic allocations, and the stack holds function calls, local variables, return addresses, and saved registers.
Q. Where are global and extern variables stored in memory?
asked 1xmediumOperating systemsTechnical2016
Ans. Global variables are stored in the program’s static storage area, mainly the data segment or BSS. Initialised globals go in the data segment, while uninitialised or zero-initialised globals go in BSS. An extern variable is only a declaration; its storage is allocated once at its actual global definition.
Q. Explain how database connections are handled using JDBC.
asked 1xmediumDBMSTechnical2019
Ans. JDBC handles database connections through a Connection object, usually obtained from a DataSource or DriverManager using a JDBC URL, username and password. The application uses this connection to create statements, execute SQL and read results. The most important detail is to close connections properly, often via try-with-resources or a connection pool.
Q. Find if a string is an interleaving of two other strings
asked 1xmediumStringsOnline test2017
Ans. Use dynamic programming to check whether each prefix of the target can be formed by interleaving prefixes of the two strings. First ensure lengths add up. Let dp[i][j] mean s3[0..i+j) can be formed from s1[0..i) and s2[0..j). Transition by matching the next character from either string. Time is O(mn), space can be O(n).
Q. Find the Longest Common Subsequence (LCS) of two strings
asked 1xmediumDynamic programmingOnline test2016
Ans. Use dynamic programming with a two-dimensional table where dp[i][j] stores the LCS length of the first i characters of one string and first j characters of the other. If characters match, extend the diagonal value; otherwise take the maximum from left or top. Time complexity is O(mn), with O(mn) space.
Q. Find the largest palindromic substring in a given string.
asked 1xmediumStringsOnline test2015
Ans. Expand around every possible centre and keep the longest palindrome seen. For each index, check both odd length and even length centres, moving left and right while characters match. This uses constant extra space and runs in O(n²) time, which is usually acceptable unless Manacher’s O(n) algorithm is specifically required.
Q. Search an element in a sorted and pivoted (rotated) array
asked 1xmediumBinary searchTechnical2021
Ans. Use modified binary search. At each step, compare the middle element with the left and right ends to find which half is sorted, then decide whether the target lies in that sorted half or the other half. No extra data structure is needed. Time complexity is O(log n), assuming distinct elements.
Q. Implement sorting of a 2-D array in the most optimized way
asked 1xmediumSortingTechnical2020
Ans. Flatten the 2-D array into a 1-D array, sort it using an efficient built-in comparison sort, then write the values back row by row. Use a dynamic array or vector to store the elements. For m rows and n columns, time complexity is O(mn log(mn)) and space is O(mn).
Q. Implement a stack data structure using queue data structure.
asked 1xmediumStack queueTechnical2019
Ans. Use one queue and make push rearrange the order so the newest element is always at the front. Enqueue the new item, then rotate all previous items to the back of the queue. Pop and top then read from the front. Push is O(n), while pop, top, and empty are O(1).
Q. Write code to implement matrix multiplication using pointers
asked 1xmediumArraysTechnical2017
Ans. Use three nested loops and pointer arithmetic to compute each result cell as the dot product of a row from the first matrix and a column from the second. Store matrices in contiguous 1D arrays, accessing element i,j as *(base + i * cols + j). Time complexity is O(r1 * c1 * c2).
Q. Search an element in a row-wise and column-wise sorted matrix
asked 1xmediumArraysTechnical2021
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. Explain the proper implementation of Depth First Search (DFS).
asked 1xmediumGraphsTechnical2020
Ans. DFS is implemented by starting at a node, marking it visited, then exploring each unvisited neighbour before backtracking. Use recursion or an explicit stack with an adjacency list. The key detail is to mark nodes as visited before continuing, so cycles do not cause repeated work. Time complexity is O(V + E).
Q. Explain virtual functions and how the compiler works with them
asked 1xmediumOOPTechnical2021
Ans. Virtual functions are member functions resolved at run time, allowing a base class pointer or reference to call the derived class implementation. The compiler usually implements this with a vtable per class and a hidden vptr in each object. Calls use the vptr to find the correct function address dynamically.
Q. Implement pattern matching with wildcard or special characters
asked 1xmediumStringsTechnical2014
Ans. Use dynamic programming where dp[i][j] means the first i text characters match the first j pattern characters. Match normal characters directly, let ? match one character, and let * match either nothing or one more character. This uses a boolean table, runs in O(nm) time and O(nm) space, reducible to O(m).
Q. What are the advantages of NoSQL databases over SQL databases?
asked 1xmediumDBMSManagerial2020
Ans. NoSQL databases are often better for flexible schemas, large-scale horizontal scaling, and high-throughput access to semi-structured or unstructured data. They suit use cases where data shape changes often or traffic is distributed across many servers. The key advantage is scalability and flexibility, usually with weaker relational guarantees than SQL databases.
Q. Convert a binary tree to its mirror using an iterative approach
asked 1xmediumTreesTechnical2016
Ans. Use an iterative traversal and swap the left and right child of every node. Start with the root in a stack or queue, repeatedly remove one node, swap its children, then add any non-null children back. This visits each node once, so time is O(n) and extra space is O(n) in the worst case.
Q. Design a website/system that can handle a large number of users
asked 1xmediumScalabilitySystem design2019
Ans. Design it as a horizontally scalable, stateless web tier behind a load balancer, backed by caching, databases, queues, and monitoring. The most important detail is removing bottlenecks: cache hot reads, use a CDN for static content, partition data when needed, process slow work asynchronously, and autoscale based on traffic and latency.
Q. Solve data interpretation problems based on graphs and pie charts.
asked 1xmediumData interpretationOnline test2019
Ans. Convert the chart information into numbers first, using percentages, angles, ratios or scale values as given. Identify exactly what is being asked, then apply the right operation: comparison, difference, percentage change, average or total. Keep units consistent, avoid assumptions, and estimate only when the graph scale clearly requires it.
Q. Count all triplets in an array whose sum is equal to a perfect cube
asked 1xmediumArraysTechnical2021
Ans. Count triplets by first generating every perfect cube between the minimum and maximum possible triplet sums, then count triplets for each cube target. Sort the array, fix one element, and use two pointers to count pairs completing the sum, handling duplicates carefully. Time complexity is O(C n²), where C is the number of cubes.
Q. Describe a situation that frustrated you and how you dealt with it.
asked 1xmediumConflict resolutionManagerial2020
Ans. Pick a work frustration caused by blockers, unclear priorities, conflict, or repeated mistakes, not personal annoyance. Emphasise staying calm, identifying the real issue, speaking directly and respectfully, and taking practical action. Interviewers listen for self-control, ownership, communication, resilience, and evidence that you improved the situation rather than blamed others.
Q. Find the Lowest Common Ancestor (LCA) of two nodes in a binary tree
asked 1xmediumTreesTechnical2021
Ans. Use a recursive depth first search: if the current root is null or equals either target node, return it. Search left and right subtrees. If both return non-null, the current root is the LCA; otherwise return the non-null side. This uses the call stack, with linear time and tree-height space.
Q. Find the length of the longest common subsequence for two given strings
asked 1xmediumDynamic programmingTechnical2016
Ans. Use dynamic programming with a table where dp[i][j] is the longest common subsequence length for the first i characters of one string and first j characters of the other. If characters match, add 1 to dp[i-1][j-1]; otherwise take the maximum of left and top. Time is O(nm), space is O(nm), or O(min(n,m)) optimised.
Q. Write an algorithm for traffic light control when all roads are two-way.
asked 1xmediumLogical designTechnical2015
Ans. Model each permitted traffic movement as a node, add an edge between movements that conflict, then repeatedly choose a maximal set of non-conflicting movements to give green together. Store conflicts as an adjacency set or bitset. This is graph colouring or greedy independent-set scheduling; one cycle takes roughly O(V²) with simple sets.
Q. What is the most difficult decision you had to make and how did you make it?
asked 1xmediumDecision makingManagerial2020
Ans. Choose a real work decision with trade-offs, not a personal drama. Emphasise the stakes, the options you considered, the evidence you gathered, who you consulted, and how you handled the consequences. Interviewers listen for judgement, ownership, calm under pressure, ethical thinking, and whether you can make decisions without perfect information.
Q. How will you handle a team member who is not contributing or not working properly?
asked 1xmediumConflict resolutionHR2021
Ans. Pick a real example where you addressed the issue early and fairly. Emphasise understanding the cause, setting clear expectations, offering support, and tracking progress. Show that you protected team delivery without blaming the person. Interviewers listen for communication, accountability, empathy, and willingness to escalate appropriately if behaviour does not improve.
Q. 25 horses puzzle: What is the minimum number of races required to find the top 3 fastest horses?
asked 1xhardLogical reasoningHR2019
Ans. 7 races. Race the horses in 5 groups of 5, then race the 5 winners. The winner of that race is fastest. Only horses that could still be second or third remain: second and third from the winner’s group, first and second from the runner-up group, and first from the third-place group. Race those 5 to decide second and third.
Showing 60 of 224 questions. Ranked by how often the same question came back across interviews.