Q. Explain ACID properties in DBMS.
asked 6xeasyDBMSManagerial, Technical2020-2023
Ans. ACID properties are the guarantees that make database transactions reliable: Atomicity, Consistency, Isolation and Durability. Atomicity means all or nothing, Consistency keeps valid rules, Isolation prevents concurrent transactions interfering, and Durability ensures committed changes survive crashes. They are essential for correctness in systems handling critical data.
Q. Print a given matrix in spiral order.
asked 4xmediumArraysOnline test, Technical2014-2020
Ans. Traverse the matrix layer by layer using four boundaries: top, bottom, left, and right. Print the top row, right column, bottom row, and left column, then move the boundaries inward. No extra data structure is needed apart from the output. Time complexity is O(mn), and space is O(1).
Q. Explain clustered and non-clustered indexes
asked 2xmediumDBMSTechnical2015
Ans. A clustered index stores table rows in the order of the index key, while a non-clustered index is a separate structure that stores key values with pointers to the actual rows. A table usually has only one clustered index, but can have many non-clustered indexes, which may need extra lookups to fetch full rows.
Q. Find the Longest Increasing Subsequence in an array
asked 2xmediumDynamic programmingTechnical2021
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. Add two numbers a and b without using the '+' operator
asked 2xmediumBit manipulationTechnical2015
Ans. Use bitwise operations: XOR gives the sum without carries, and AND followed by a left shift gives the carry. Repeat with a = a XOR b and b = (a AND b) << 1 until the carry becomes zero. This uses only integer variables, runs in O(number of bits), and uses O(1) space.
Q. Write an algorithm for the Dutch National Flag problem.
asked 2xmediumArraysOnline test2014-2015
Ans. Use three pointers, low, mid and high, to partition the array in one pass. While mid is at or before high, swap 0s to low and advance both, leave 1s by advancing mid, and swap 2s to high while only moving high. This runs in O(n) time and O(1) space.
Q. Sort a matrix such that rows are in ascending order and columns are in descending order
asked 2xhardArraysTechnical2014
Ans. Flatten the matrix, sort all elements in ascending order, then fill the matrix from the bottom row to the top row, left to right in each row. Each row will be ascending, and every higher row will contain larger values than the row below. Use an auxiliary array. Time complexity is O(mn log mn).
Q. Detect a loop in a linked list
asked 2xeasyLinked listsTechnical2014-2021
Ans. Use Floyd’s cycle detection with two pointers, slow and fast, starting at the head. Move slow one node at a time and fast two nodes at a time. If they ever meet, there is a loop. If fast reaches null, there is no loop. This runs in O(n) time and O(1) space.
Q. Check whether a linked list is circular
asked 2xeasyLinked listsTechnical2014-2021
Ans. Use Floyd’s slow and fast pointer method to detect whether the linked list has a cycle. Move slow by one node and fast by two nodes; if they ever meet, the list is circular or cyclic. If fast reaches null, it is not circular. This uses constant extra space and runs in O(n) time.
Q. Explain the ACID properties in databases.
asked 2xeasyDBMSTechnical2019-2021
Ans. ACID properties are guarantees that make database transactions reliable: Atomicity, Consistency, Isolation, and Durability. Atomicity means all changes commit or none do. Consistency keeps data valid under rules and constraints. Isolation makes concurrent transactions behave safely. Durability means committed changes survive crashes, usually through logging and persistent storage.
Q. Find the Nth term of the Fibonacci series.
asked 2xeasyDynamic programmingOnline test2019
Ans. Find it by iterating from the first two Fibonacci values and keeping only the previous two terms. If using zero-based indexing, F0 is 0 and F1 is 1; repeatedly set next to prev plus curr until N. This takes O(N) time and O(1) space.
Q. Add two numbers without using the '+' operator
asked 2xeasyBit manipulationTechnical2014-2015
Ans. Use bitwise operations: XOR gives the sum without carries, and AND followed by a left shift gives the carry. Repeat until the carry becomes zero, then the XOR result is the answer. No extra data structure is needed. Time complexity is O(number of bits), usually O(1) for fixed-width integers.
Q. Given a number, find the nearest prime number.
asked 2xeasyMathOnline test, Technical2016-2021
Ans. Check the number itself, then expand outwards by testing n minus 1, n plus 1, n minus 2, n plus 2, and so on until a prime is found. Test primality by trying divisors up to the square root. Use no special data structure. Time is O(d sqrt n), where d is the distance to the nearest prime.
Q. Difference between encapsulation and abstraction
asked 2xeasyOOPTechnical2015
Ans. Abstraction hides unnecessary details by exposing what an object does, while encapsulation hides internal state and implementation by controlling how data is accessed or changed. Abstraction is about designing a simple interface. Encapsulation is about protecting data, usually by keeping fields private and using methods to enforce valid behaviour.
Q. Sort an array consisting only of 0s, 1s, and 2s.
asked 2xeasyArraysOnline test2015-2016
Ans. Use the Dutch National Flag approach with three pointers: low, mid, and high. Scan once: move 0s to the front, 2s to the end, and leave 1s in the middle. This sorts the array in place using constant extra space, with O(n) time complexity.
Q. Explain runtime polymorphism in Object-Oriented Programming
asked 2xeasyOOPTechnical2021-2023
Ans. Runtime polymorphism means the method that runs is chosen at execution time based on the actual object type, not the reference type. It is usually achieved through method overriding, where a subclass provides its own implementation of a method declared in a parent class or interface. This enables flexible, extensible code.
Q. Aptitude and logical reasoning questions
asked 2xunknownLogical reasoningOnline test2015-2023
Ans. Identify the question type first, then write down the given facts clearly. Convert words into equations, tables, diagrams, or sequences where useful. Eliminate impossible options and check units, order, and conditions carefully. For reasoning puzzles, test one assumption at a time and verify the final answer against every statement.
Q. Common logical puzzles
asked 1xmediumLogical reasoningOnline test2016
Ans. I would solve it by defining the facts, listing constraints, and testing possibilities systematically. If there is a numerical pattern, I check differences, ratios, and edge cases. If it is a truth-teller puzzle, I build a truth table. The answer depends on the exact puzzle, but the key is disciplined elimination.
Q. Chocolate Distribution Problem
asked 1xmediumArraysOnline test2021
Ans. Sort the packet sizes, then check every group of m consecutive packets and return the minimum difference between the largest and smallest in such a group. Sorting makes the chosen packets adjacent in an optimal solution. Use no extra data structure beyond variables for the best answer. Time complexity is O(n log n).
Q. Write an SQL query for a given table
asked 1xmediumSQLTechnical2021
Ans. Use a SELECT query that names the required columns, reads from the given table, filters rows with WHERE, groups with GROUP BY if aggregates are needed, filters groups with HAVING, and sorts with ORDER BY. The key detail is to match the query to the required output, especially joins, aggregation, and duplicate handling.
Q. Find the majority element in an array
asked 1xmediumArraysOnline test2021
Ans. Use the Boyer Moore voting algorithm to find the majority element in one pass. Keep a candidate and a count: set the candidate when count is zero, increment for matches, decrement otherwise. If a majority is not guaranteed, verify the candidate with a second pass. Time is O(n), space is O(1).
Q. Solve logical puzzles (2–3 questions)
asked 1xmediumLogical reasoningOnline test2014
Ans. I would first clarify the rules and assumptions, then reduce the puzzle to cases or constraints. I would test each case systematically, eliminate contradictions, and keep track of what must be true. If a unique answer remains, I would state it and briefly verify it against the original conditions.
Q. Print the right view of a binary tree.
asked 1xmediumTreesTechnical2017
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. Explain thrashing in operating systems.
asked 1xmediumOperating systemsManagerial2023
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. Find the k-th largest number in an array.
asked 1xmediumArraysTechnical2022
Ans. Use a min-heap of size k. Insert each number, and whenever the heap grows beyond k, remove the smallest. After scanning the array, the heap root is the k-th largest number, counting duplicates. This takes O(n log k) time and O(k) extra space.
Q. Print all permutations of a given string.
asked 1xmediumBacktrackingTechnical2016
Ans. Use backtracking to build permutations by choosing each unused character in turn, recursing until the current string has the original length, then print it. Keep a character array, a boolean used array, and a temporary result buffer. The time complexity is O(n × n!) and the recursion depth is O(n).
Q. Find the k-th largest element in an array.
asked 1xmediumArraysOnline test2022
Ans. Use a min-heap of size k: insert each element, and whenever the heap grows beyond k, remove the smallest. After processing the array, the heap root is the k-th largest element. This takes O(n log k) time and O(k) space, and handles duplicates naturally.
Q. What is 3NF and how is it better than 2NF?
asked 1xmediumDBMSManagerial2023
Ans. 3NF, or third normal form, is a database design rule where a table is in 2NF and has no transitive dependencies between non-key attributes. In 2NF, non-key columns must depend on the whole key. 3NF goes further by ensuring non-key columns depend only on the key, reducing duplication and update anomalies.
Q. Search an element in a rotated sorted array.
asked 1xmediumBinary searchTechnical2021
Ans. Use a modified binary search: compare the middle element with the ends to decide which half is sorted, then check whether the target lies inside that sorted half. If it does, search there, otherwise search the other half. For distinct elements, this takes O(log n) time and O(1) space.
Q. Serialize and deserialize a given n-ary tree
asked 1xmediumTreesTechnical2015
Ans. Serialize the n-ary tree using preorder traversal, writing each node’s value followed by its number of children. To deserialize, read the stream in order: create the node, read its child count, then recursively build that many children. Store tokens in an array or queue. Both operations take O(n) time and O(n) space.
Q. Sort an array containing only 0s, 1s, and 2s
asked 1xmediumArraysOnline test2016
Ans. Use the Dutch National Flag approach with three pointers: low, mid, and high. Scan once, swapping 0s to the front, 2s to the back, and leaving 1s in the middle. This sorts the array in place with O(n) time complexity and O(1) extra space.
Q. What is indexing in DBMS? Explain its types.
asked 1xmediumDBMSTechnical2017
Ans. Indexing in DBMS is a technique that creates a separate data structure to find rows faster without scanning the whole table. Common types include primary index, secondary index, clustered index, non-clustered index, dense index, and sparse index. Indexes speed up reads but add storage cost and slow inserts, updates, and deletes.
Q. Write an SQL query involving JOIN operations
asked 1xmediumSQLTechnical2020
Ans. Use an INNER JOIN to combine rows from two tables where their related keys match, such as customers joined to orders on customer ID. Select the needed columns from both tables, name each table clearly, and put the join condition in the ON clause. With indexed join keys, lookup is typically efficient.
Q. Find the largest rectangle area in a histogram
asked 1xmediumStacksTechnical2023
Ans. Use a monotonic increasing stack of bar indices to find the largest rectangle in O(n) time. Scan left to right, and when the current height is lower than the stack top, pop bars and compute area using the popped height and the width between the new stack top and current index. Add a zero-height sentinel at the end.
Q. Find the nth Fibonacci number in O(log n) time
asked 1xmediumDynamic programmingTechnical2015
Ans. Use fast doubling to compute the Nth Fibonacci number in O(log n) time by recursively calculating pairs F(k) and F(k + 1). The key formulas are F(2k) = F(k) × [2F(k + 1) − F(k)] and F(2k + 1) = F(k)^2 + F(k + 1)^2. Space is O(log n).
Q. Implement merge sort for a singly linked list.
asked 1xmediumLinked listsTechnical2015
Ans. Use merge sort by splitting the list with slow and fast pointers, sorting each half recursively, then merging the two sorted lists by relinking existing nodes. The key detail is to cut the list at the midpoint before recursion. It runs in O(n log n) time and uses O(log n) stack space.
Q. Logical puzzles commonly asked in aptitude tests
asked 1xmediumLogical reasoningOnline test2021
Ans. Use a structured approach: identify the given facts, translate them into simple statements or a table, then eliminate impossible options step by step. Check each remaining option against every condition. If there is one valid arrangement, that is the answer. If more than one remains, the puzzle lacks enough information.
Q. Find the contiguous subarray with the largest sum
asked 1xmediumArraysTechnical2021
Ans. Use Kadane’s algorithm: scan the array, keeping the best sum ending at the current index and the best sum seen overall. At each element, either extend the previous subarray or start a new one there. Initialise with the first element to handle all negative arrays. Time is O(n), space is O(1).
Q. Find the missing and repeating number in an array
asked 1xmediumArraysOnline test2015
Ans. Use the sum and sum of squares of numbers from 1 to n compared with the array’s sum and square sum to derive two equations for the missing and repeating values. Solve them to get both numbers. This uses no extra data structure, runs in O(n) time, and O(1) space.
Q. Print characters in decreasing order of frequency
asked 1xmediumStringsTechnical2021
Ans. Count the frequency of each character, then print characters sorted by decreasing count. Use a hash map or fixed-size array for frequencies, then sort the characters by frequency descending. If ties matter, apply the required secondary order. Time complexity is O(n + k log k), where k is the number of distinct characters.
Q. Write SQL queries to retrieve and manipulate data
asked 1xmediumSQLTechnical2021
Ans. Use SELECT to retrieve data, with WHERE, JOIN, GROUP BY and ORDER BY to filter, combine, aggregate and sort results. Use INSERT, UPDATE and DELETE to manipulate rows, ideally inside transactions when changes must be atomic. The key detail is to target rows precisely, especially for UPDATE and DELETE, to avoid unintended changes.
Q. Find the k-th non-repeating character in a string.
asked 1xmediumStringsOnline test2021
Ans. Count character frequencies, then scan the string again and return the k-th character whose frequency is one. Use a hash map or fixed-size array for counts, depending on the character set. If fewer than k non-repeating characters exist, return a sentinel value. Time is O(n), space is O(1) or O(m).
Q. Why is virtual memory needed in operating systems?
asked 1xmediumOperating systemsManagerial2023
Ans. Virtual memory is needed to give each process its own private, continuous address space, independent of physical RAM. It lets the OS map virtual pages to physical frames, protect processes from each other, load only needed pages, and use disk as backing store when memory is limited.
Q. Design an algorithm for the Snake and Ladder problem
asked 1xmediumGraphsTechnical2014
Ans. Use breadth first search on board positions to find the minimum dice throws from square 1 to square N. Treat each square as a graph node, and each dice roll as an edge to the final square after applying any snake or ladder. Use a queue and visited array. Time complexity is O(N), with O(N) space.
Q. Detect whether a linked list contains a loop (cycle).
asked 1xmediumLinked listsOnline test2016
Ans. Use Floyd’s cycle detection with two pointers, slow and fast. Move slow one node at a time and fast two nodes at a time. If they ever meet, the list has a loop. If fast reaches null, there is no loop. This runs in O(n) time and O(1) space.
Q. What is a semaphore? Explain the types of semaphores.
asked 1xmediumOperating systemsTechnical2015
Ans. A semaphore is a synchronisation primitive used to control access to shared resources by multiple processes or threads. It maintains a counter changed by wait and signal operations. The main types are binary semaphores, which allow only 0 or 1 and act like a lock, and counting semaphores, which allow a limited number of concurrent accesses.
Q. Write an SQL query using JOINs to fetch required data
asked 1xmediumSQLTechnical2022
Ans. Use a SELECT from the main table, join related tables on their primary key and foreign key columns, then filter with WHERE and choose only needed columns. Use INNER JOIN when matching rows are required, and LEFT JOIN when main table rows must remain even without matches. Performance mainly depends on indexed join keys.
Q. Explain the order of execution for sample SQL queries.
asked 1xmediumSQLTechnical2015
Ans. SQL queries are logically executed as FROM and JOIN first, then WHERE, GROUP BY, HAVING, SELECT, DISTINCT, ORDER BY, and finally LIMIT or OFFSET. The key detail is that SELECT aliases are usually not available in WHERE because filtering happens before the SELECT list is produced. Actual database engines may optimise the physical order.
Q. Write SQL queries based on common database operations.
asked 1xmediumSQLTechnical2014
Ans. Use SELECT for reading rows, INSERT for adding rows, UPDATE for changing existing rows, DELETE for removing rows, and JOIN when data spans tables. Filter with WHERE, group with GROUP BY, restrict grouped results with HAVING, and sort with ORDER BY. Performance mainly depends on indexes, table size, joins, and selectivity.
Q. Explain the algorithm for the Snake and Ladder problem.
asked 1xmediumGraphsTechnical2014
Ans. Use breadth first search, treating each square as a node and each dice throw as an edge to the next 1 to 6 squares. If a move lands on a snake or ladder, move directly to its destination. Track visited squares and distance in a queue. The first time you reach the last square is the minimum throws.
Q. Solve the 2 eggs puzzle to determine the critical floor
asked 1xmediumLogical reasoningTechnical2015
Ans. Use decreasing step sizes so the worst case is balanced. For 100 floors, drop first at 14, then 27, 39, 50, 60, 69, 77, 84, 90, 95, 99, 100. If it breaks, test linearly from the previous safe floor. Since 14 + 13 + ... + 1 = 105, at most 14 drops are needed.
Q. Write SQL queries for given tables based on requirements
asked 1xmediumSQLTechnical2020
Ans. I would write the query by mapping each requirement to SELECT columns, FROM tables, JOIN conditions, WHERE filters, GROUP BY aggregation, and ORDER BY sorting. The key detail is using the correct join keys and aggregation level, because most SQL mistakes come from duplicate rows or grouping at the wrong granularity.
Q. Check whether a given binary tree is a binary search tree.
asked 1xmediumTreesTechnical2015
Ans. Check it by doing a DFS with valid lower and upper bounds for each node. A node must be greater than its lower bound and less than its upper bound, then pass updated bounds to its children. Use recursion or an explicit stack. Time is O(n) and space is O(h).
Q. Design an ATM machine, including its use cases and design considerations.
asked 1xmediumDesignSystem design2019
Ans. An ATM should authenticate a cardholder, let them check balance, withdraw, deposit, transfer funds, change PIN, and print or display receipts. The key design concern is transactional safety: every cash dispense and account update must be atomic, auditable, secure, fault tolerant, and recoverable across network failures, power loss, and hardware errors.
Q. What steps would you take to improve the response time of a slow website?
asked 1xmediumScalabilityHR2020
Ans. I would measure first, then optimise the biggest bottleneck, starting with server, database, network, and browser timings. The key detail is to use real metrics such as p95 latency, traces, and logs, not guesses. Common fixes include caching, database indexing, reducing payload size, using a CDN, async work, and scaling hot services.
Q. Solve time and work problems involving multiple workers and varying efficiencies
asked 1xmediumTime and workOnline test2016
Ans. Convert each worker’s efficiency into work done per unit time, usually as a fraction of the whole job. Add rates when people work together, subtract rates if someone undoes work, and adjust rates for different efficiencies. Total work is often taken as 1 or the LCM of individual times, then use time equals work divided by combined rate.
Q. Derive and prove the general formula for number of squares in an n x n chessboard.
asked 1xmediumLogical reasoningTechnical2015
Ans. The number of squares is n(n+1)(2n+1)/6. Count by size: there are n² squares of size 1 by 1, (n−1)² of size 2 by 2, and so on, down to 1² of size n by n. Thus total = 1² + 2² + ... + n² = n(n+1)(2n+1)/6.
Q. Design a system to check whether people are following social distancing while passing through a society gate
asked 1xmediumDesignHR2020
Ans. Use a gate-mounted camera with a real-time video pipeline that detects people, tracks them across frames, estimates ground-plane distance, and raises an alert when two people remain too close for a configured duration. The key detail is camera calibration, because pixel distance must be converted into real-world distance reliably for that gate layout.
Q. Should courses like NPTEL be encouraged despite lowering student attendance in colleges?
asked 1xunknownVerbalGroup discussion2016
Ans. A strong answer should support NPTEL while acknowledging attendance concerns. Pick a balanced view: online courses add depth, expert access and flexibility, but should complement college teaching. Emphasise blended learning, credits, mentoring and attendance linked to active engagement. Interviewers listen for maturity, respect for institutions and practical solutions rather than a one-sided opinion.
Q. How will you manage to complete a given task if the deadline is near and the task is not yet completed?
asked 1xunknownTime managementManagerial2022
Ans. Pick a real example where you stayed calm, reassessed priorities, and communicated early. Emphasise breaking the work into critical parts, asking for help if needed, managing scope, and giving regular updates. Interviewers listen for ownership, judgement, transparency, and focus on delivering the most important outcome rather than panicking or hiding delays.
Showing 60 of 343 questions. Ranked by how often the same question came back across interviews.