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. 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. 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. 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. 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. Rotate a linked list in groups of k.
asked 1xmediumLinked 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. 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. 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 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. 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. 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 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 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. 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. 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. 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 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. Find the kth largest element in an unsorted array and write complete code
asked 1xmediumArraysTechnical2019
Ans. Use Quickselect to find the kth largest element by partitioning around a pivot until the pivot index is n minus k. It works like Quicksort partitioning but only recurses into one side. The main data structure is the input array itself. Average time is O(n), worst case O(n²), space is O(1).
Q. Write a program to find the longest common substring between two strings.
asked 1xmediumDynamic programmingTechnical2017
Ans. Use dynamic programming to store the length of the common suffix ending at each pair of positions. If the characters match, set the cell to the diagonal value plus one, otherwise set it to zero. Track the maximum length and end index. Time is O(nm), space can be O(min(n,m)) with rolling rows.
Q. Remove every k-th person from total of n persons sitting in a round circle
asked 1xmediumRecursionOnline test2017
Ans. Use the Josephus problem. Maintain the current index as (index + k - 1) % remaining_people, remove that person, and continue until one remains. For only the survivor, use the recurrence iteratively in O(n) time and O(1) space. For removal order, use a circular list or queue.
Q. Find duplicate elements in an array with O(n) time and constant extra space
asked 1xmediumArraysTechnical2019
Ans. Use the array itself to mark seen values, assuming elements are in the range 1 to n. For each value x, look at index abs(x) minus 1. If that position is already negative, x is a duplicate; otherwise negate it. This runs in O(n) time and O(1) extra space, but modifies the array.
Q. How are AI/ML techniques like SVM, ANN, or GP better than linear regression?
asked 1xmediumMachine learningTechnical2014
Ans. SVMs, ANNs and GPs can model complex, non-linear relationships that linear regression cannot capture well. Linear regression assumes a straight-line relationship between inputs and output, while these methods can learn curved boundaries, interactions and high-dimensional patterns. They may be more accurate, but usually need more data, tuning and computation.
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. Given two tables, find the person who has placed the maximum number of orders
asked 1xmediumSQLTechnical2021
Ans. Join the people table to the orders table, group by person, count the orders for each person, then return the person with the highest count. In SQL, this is usually done with GROUP BY and COUNT, ordered descending with a limit of one. Use RANK if ties must be returned.
Q. Design a future washing machine using a block diagram and explain its working.
asked 1xmediumHigh level designTechnical2015
Ans. A future washing machine can be designed as: Sensors and user app to AI controller to motor, valves, heater, detergent pump and drain, with cloud diagnostics and power management. The controller weighs clothes, detects fabric and dirt, selects water, detergent, temperature and drum motion, then monitors vibration, leakage and energy use to adjust the cycle safely.
Q. Explain trees and their types, including Binary Search Tree (BST) and AVL Tree.
asked 1xmediumTreesTechnical2020
Ans. A tree is a hierarchical data structure of nodes connected by edges, with one root and no cycles. Common types include binary trees, n-ary trees, heaps, tries, BSTs and AVL trees. In a BST, left values are smaller and right values larger. An AVL tree is a self-balancing BST, keeping search, insert and delete O(log n).
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. Save Gotham (find the next greater element for each element in an array and sum them)
asked 1xmediumStackTechnical2018
Ans. Use a monotonic decreasing stack to find the next greater element for each array value, then add those values to the answer. Traverse from right to left, popping all elements less than or equal to the current value. The stack top is the next greater element, or -1 if empty. Time complexity is O(n).
Q. What is the trivial condition for Binary Search and what is the logic behind Ternary Search?
asked 1xmediumSearchingTechnical2020
Ans. The trivial condition for binary search is that the search interval becomes empty, usually low greater than high, so the element is not present. Ternary search divides the range into three parts using two midpoints. By comparing the target or function values at those points, it discards one part and continues in the remaining range.
Q. Design the database schema (tables and relationships) for a computer center management system.
asked 1xmediumDBMSTechnical2016
Ans. Use tables for Computers, Users, Staff, Sessions, Bookings, Payments and Maintenance. Computers store lab, status and specifications. Users make Bookings and start Sessions on one Computer. Sessions record start, end, charge and Payment. Staff handle Maintenance records for Computers. The key detail is enforcing foreign keys and preventing overlapping bookings per computer.
Q. Given two sorted linked lists, merge them in sorted order and then reverse the resulting list.
asked 1xmediumLinked listsOnline test2019
Ans. Merge the two sorted linked lists with two pointers, building one sorted list, then reverse that merged list by relinking pointers. Use a dummy head for simpler merging, then iterate through the merged list with previous, current, and next pointers. The time complexity is O(m+n) and space is O(1).
Q. Design a modern car by drawing its block diagram and explain the functionality of each component.
asked 1xmediumHigh level designTechnical2015
Ans. A modern car can be modelled as sensors and controls feeding ECUs, connected by CAN or Ethernet, driving powertrain, braking, steering, body, infotainment and safety actuators. Sensors measure speed, position, temperature and surroundings. ECUs compute control actions. The network carries messages. Actuators execute commands, while diagnostics, battery management and security monitor reliability.
Q. Given a table representing directory details, check whether the given directory structure is correct
asked 1xmediumSQLTechnical2021
Ans. Validate it by treating each directory as a node in a tree and checking that the table forms one valid rooted hierarchy. Store entries in a hash map by directory id, verify every non-root parent exists, ensure there is exactly one root, and run DFS with visited states to detect cycles. Time complexity is O(n).
Q. How many squares of side length a can fit inside a triangle of height h and base b? Derive the formula
asked 1xmediumGeometryTechnical2014
Ans. For squares aligned with the base, use the triangle’s linear narrowing. At height y, available width is b(1 - y/h). In the kth row from the bottom, the square top is at y = ka, so squares in that row are floor(b(h - ka)/(ah)). Total = sum from k = 1 to floor(h/a) of that value.
Q. Given a code snippet, identify whether it demonstrates compile-time polymorphism or run-time polymorphism
asked 1xmediumOOPTechnical2023
Ans. It is compile-time polymorphism if the snippet uses method overloading, operator overloading, or templates, and run-time polymorphism if it uses method overriding through inheritance. The key detail is binding: compile-time polymorphism is resolved by the compiler, while run-time polymorphism is resolved during execution using dynamic dispatch.
Q. Given millions of data points with values in the range 1 to 300, which sorting technique is best and why?
asked 1xmediumSortingTechnical2020
Ans. Counting sort is best because the value range is very small and fixed, from 1 to 300. Count how many times each value appears, then output values in order using those counts. This avoids comparisons and runs in O(n + 300) time with O(300) extra space.
Q. Design a database to assign classes based on availability and facilities such as projectors and computer systems.
asked 1xmediumDb designTechnical2017
Ans. Use a relational database with tables for Rooms, Facilities, RoomFacilities, Classes, TimeSlots and Bookings. Store room capacity, location and status, and map each room to facilities such as projector or computers. The key detail is enforcing no overlapping bookings for the same room, then querying free rooms that match required capacity and facilities.
Q. Given numbers from 1 to N with exactly one number missing and one repeated, find the missing and the repeated number.
asked 1xmediumArraysOnline test2015
Ans. Use the sum and sum of squares formulas to get two equations for the missing and repeated numbers. Let the expected sums for 1 to N be compared with the actual array sums. Their differences give m minus r and m squared minus r squared, so solve for both. This uses O(1) space and O(N) time.
Q. Explain Support Vector Machines (SVM), Artificial Neural Networks (ANN), and Genetic Programming (GP) and compare them
asked 1xmediumMachine learningTechnical2014
Ans. SVMs are supervised models that find a maximum-margin boundary, ANNs learn layered non-linear representations from data, and GP evolves programs or expressions using selection and mutation. SVMs work well on smaller structured data, ANNs need more data and compute but model complex patterns, while GP is useful for search and symbolic solutions.
Q. Given a recommendation system with O(n^3) time complexity, how would you optimize it to work on a large-scale database?
asked 1xmediumPerformance optimizationTechnical2019
Ans. I would avoid comparing every user and item combination by moving to a two-stage design: generate a small candidate set, then rank it. Precompute user and item embeddings offline, store them in an approximate nearest neighbour index, and update incrementally. This reduces online work from cubic to near logarithmic or sublinear lookup plus ranking.
Q. How would you adapt a recommendation system if the arbitrarily assigned feature priorities do not match user preferences?
asked 1xmediumRecommendation systemTechnical2019
Ans. I would replace fixed feature priorities with learned weights driven by user behaviour and explicit feedback. Log impressions, clicks, skips, purchases, ratings, and dwell time, then train or fine-tune a ranking model to optimise relevance. The key detail is to evaluate changes with offline metrics and A/B tests, not assumptions.
Q. Given arrival and departure times of buses at a depot, find the minimum number of bus stands required so that no bus has to wait.
asked 1xmediumGreedyOnline test2016
Ans. Sort the arrival and departure times separately, then sweep them with two pointers to count how many buses are present at once. If the next arrival is before or at the next departure, add a stand and update the maximum; otherwise free one. This runs in O(n log n) time.
Q. Design a system for an online milk vendor to manage suppliers, customer coupons, coupon expiry, staff handling, and milk price notifications
asked 1xmediumLow level designTechnical2017
Ans. Use a modular backend with services for suppliers, inventory, coupons, orders, staff roles, and notifications, backed by a relational database. Store coupon validity, usage limits, customer mapping, and expiry dates, with scheduled jobs to expire coupons. Use role-based access for staff actions, audit logs, and a message queue to send milk price change notifications.
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 145 questions. Ranked by how often the same question came back across interviews.