Q. Reverse a string without using any loop.
asked 2xmediumStringsTechnical2015
Ans. Use recursion to reverse the string by taking the last character and appending the reverse of the remaining prefix. The call stack acts as the data structure, so no explicit loop is used. This takes O(n) time, but also O(n) extra space because of recursive calls and string creation.
Q. Find the day of the month using two dice.
asked 2xmediumProbabilityTechnical2015
Ans. Put digits on two cubes as follows: first die 0, 1, 2, 3, 4, 5; second die 0, 1, 2, 6, 7, 8. Use the 6 upside down as 9. Both dice need 0, 1 and 2 for 01, 11 and 22; only one 3 is needed for 30 and 31.
Q. Measure exactly 15 minutes using two sand timers of 7 minutes and 11 minutes.
asked 2xmediumLogical reasoningTechnical2015
Ans. Start both timers together. When the 7 minute timer finishes, at 7 minutes, flip it. When the 11 minute timer finishes, at 11 minutes, flip the 7 minute timer again. It has run for 4 minutes since being flipped, so 4 minutes of sand remains to run. It finishes at 15 minutes.
Q. Explain polymorphism in C++ including function overloading, function overriding, and virtual functions with code examples.
asked 2xmediumOOPTechnical2015
Ans. Polymorphism in C++ means the same interface can behave differently depending on argument types or the actual object type. Function overloading is compile-time, such as print(int) and print(string). Function overriding is run-time, where a derived class redefines a base method. Virtual functions enable calls through base pointers to dispatch to the derived implementation.
Q. Print numbers from 100 to 1000 without using loops or recursion.
asked 2xhardLogical reasoningTechnical2015
Ans. Use a built-in range or sequence generator and pass it to a printing or joining routine, so your code has no explicit loop or recursion. The important caveat is that iteration still happens inside the library. It prints 901 numbers, so the time is O(n), with O(1) extra space if streamed.
Q. Explain the differences between C and C++.
asked 2xeasyOOPTechnical2015
Ans. C is a procedural language, while C++ is largely a superset of C with object oriented and generic programming features. C++ adds classes, inheritance, polymorphism, templates, exceptions, references, function overloading and the standard library. The most important difference is abstraction: C gives low level control, while C++ supports higher level design without losing that control.
Q. Reverse a number without using extra space.
asked 2xeasyMathTechnical2015
Ans. Reverse it by repeatedly taking the last digit with modulo 10, appending it to a result using result times 10 plus digit, and removing the digit with integer division by 10. Keep the sign separately if needed. This uses only integer variables, so space is O(1), and time is O(digits).
Q. Explain the basics of hashing and how it works.
asked 2xeasyDsaTechnical2015
Ans. Hashing maps data, usually a key, to a fixed-size value using a hash function. In a hash table, that value decides where the item is stored, making lookup, insert and delete average O(1). The key detail is collision handling, because different keys can produce the same hash, often managed by chaining or probing.
Q. Explain inorder, preorder, and postorder traversal of a binary tree.
asked 2xeasyTreesTechnical2015
Ans. Inorder visits left subtree, node, then right subtree; preorder visits node, left, then right; postorder visits left, right, then node. They are depth first traversals, usually implemented recursively or with a stack. Each visits every node once, so the time complexity is O(n). Inorder gives sorted order for a binary search tree.
Q. Sort a linked list.
asked 1xmediumLinked listsTechnical2014
Ans. Use merge sort, because linked lists can be split and merged without random access. Find the middle with slow and fast pointers, recursively sort both halves, then merge two sorted lists by relinking nodes. This takes O(n log n) time and O(log n) stack space, or O(1) extra space if done bottom-up.
Q. Train puzzle problem.
asked 1xmediumLogical reasoningTechnical2014
Ans. Use relative speed, not the fly’s back-and-forth trips. If two trains are D apart and move towards each other at speeds u and v, they meet after D divided by u plus v. A fly travelling at speed f covers f times that time. For 100 miles, 50 mph each, fly 75 mph, the answer is 75 miles.
Q. Petrol tank puzzle problem.
asked 1xmediumLogical reasoningTechnical2014
Ans. Assuming the classic convoy version, with n full tanks and cars may be abandoned, the maximum distance for one car is tank range times Hn. Drive all n cars until one tankful has been consumed, transfer fuel, drop one car, and repeat. For n cars, answer is R(1 + 1/2 + ... + 1/n).
Q. Detect a cycle in a linked list.
asked 1xmediumLinked listsTechnical2015
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 the Spring Bean lifecycle
asked 1xmediumSpringTechnical2019
Ans. The Spring Bean lifecycle is creation, dependency injection, initialisation, use, and destruction by the Spring container. Spring instantiates the bean, sets its properties, calls aware interfaces and BeanPostProcessors, runs init methods such as @PostConstruct, then serves it. On shutdown it calls destroy callbacks such as @PreDestroy for singleton beans.
Q. Explain Hibernate caching mechanisms
asked 1xmediumHibernateTechnical2019
Ans. Hibernate uses first-level, second-level, and query caching to reduce database access. The first-level cache is mandatory and scoped to a Session. The second-level cache is optional and shared across Sessions via a provider like Ehcache or Infinispan. Query cache stores query result identifiers, but works best with second-level cache enabled.
Q. Explain referential integrity in DBMS
asked 1xmediumDBMSTechnical2015
Ans. Referential integrity is a database rule that keeps relationships between tables consistent, usually by ensuring every foreign key value matches an existing primary key value in the referenced table. The key detail is that it prevents orphan records, such as an order pointing to a customer that does not exist.
Q. Design test cases for a given scenario.
asked 1xmediumSoftware testingHR2014
Ans. I would design tests by covering the main user flow, boundary values, invalid inputs, error handling, security checks, performance expectations, and recovery cases. The key detail is to derive cases from requirements and risk, so positive, negative, edge, and regression tests all map back to expected behaviour.
Q. Explain thrashing in operating systems.
asked 1xmediumOperating systemsTechnical2016
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. How does Kafka maintain data consistency?
asked 1xmediumDistributed systemsTechnical2024
Ans. Kafka maintains data consistency by writing records to an ordered, append-only log per partition and replicating that log from a leader broker to follower brokers. The key detail is the in-sync replica set: with appropriate acks and minimum in-sync replicas, Kafka only acknowledges writes that are safely replicated, preserving order and durability.
Q. Remove a loop from a circular linked list
asked 1xmediumLinked listsTechnical2015
Ans. Use Floyd’s slow and fast pointers to detect the loop, then find the first node of the loop and break it. After slow and fast meet, move one pointer to head and advance both one step until they meet. Then traverse the loop to find the node pointing to that start node and set its next to null. Time is O(n).
Q. Detect and remove a cycle in a linked list
asked 1xmediumLinked listsTechnical2014
Ans. Use Floyd’s slow and fast pointer method to detect the cycle, then find the cycle start and break the link just before it. After detection, reset one pointer to the head and move both one step until they meet. Then traverse the loop to its last node and set its next to null. O(n) time, O(1) space.
Q. How is durability maintained in a database?
asked 1xmediumDBMSTechnical2016
Ans. Durability is maintained by ensuring that once a transaction is committed, its changes survive crashes or power loss. The key mechanism is usually write-ahead logging: the database writes the transaction details to stable storage before confirming commit, then uses that log to redo committed changes during recovery.
Q. Write a complete working code for Merge Sort
asked 1xmediumSortingTechnical2014
Ans. Use divide and conquer: recursively split the array into two halves until each part has one element, then merge sorted halves back into a sorted array. The key data structure is an auxiliary array used during merging. Merge Sort runs in O(n log n) time and uses O(n) extra space.
Q. Print odd and even numbers using two threads.
asked 1xmediumMultithreadingTechnical2024
Ans. Use two threads sharing a counter, with one thread responsible for odd numbers and the other for even numbers. Protect the counter with a lock and use a condition or wait and notify so each thread sleeps until it is its turn. Increment after printing. Time complexity is linear in the number of values printed.
Q. Explain the internal working of LinkedHashMap.
asked 1xmediumOOPTechnical2024
Ans. LinkedHashMap works like a HashMap for lookup, but each entry is also part of a doubly linked list. The hash table gives average constant time get, put and remove, while the linked list preserves iteration order. By default it keeps insertion order, or access order if configured, useful for LRU caches.
Q. Explain the Executor Framework with an example.
asked 1xmediumOOPTechnical2024
Ans. The Executor Framework in Java provides a higher-level way to run asynchronous tasks using managed thread pools instead of creating threads manually. For example, a fixed thread pool can process many file uploads by submitting each upload as a Runnable or Callable. It improves resource control, reuse, scheduling, and result handling through Future.
Q. Explain the internal working of HashMap in Java
asked 1xmediumData structuresTechnical2019
Ans. A HashMap stores key value pairs in an internal array of buckets, using the key’s hashCode to choose a bucket index. If multiple keys land in the same bucket, it compares keys with equals and stores collisions in a linked list or, after enough collisions, a tree. Resizing happens when the load factor threshold is crossed.
Q. Implement the Producer-Consumer problem in Java
asked 1xmediumOperating systemsTechnical2020
Ans. Use a bounded BlockingQueue in Java, with producers calling put() and consumers calling take(). The queue is the shared buffer and handles synchronisation, blocking producers when full and consumers when empty. Common choices are ArrayBlockingQueue or LinkedBlockingQueue. Each put and take is O(1) in normal operation.
Q. Logical reasoning problems of varying difficulty.
asked 1xmediumLogical reasoningOnline test2014
Ans. Break the problem into facts, rules, and conclusions. Identify what must be true, what may be true, and what cannot be true. Use diagrams, tables, or symbols for relationships. Eliminate options that break a rule. For harder questions, test cases systematically and avoid assumptions not stated in the question.
Q. Detect a loop in a linked list using two pointers.
asked 1xmediumLinked listsTechnical2014
Ans. Use Floyd’s cycle detection with a slow pointer moving one node at a time and a fast pointer moving two nodes at a time. If they ever meet, there is a loop; if the fast pointer reaches null, there is no loop. This uses constant extra space and runs in linear time.
Q. Explain lambda expressions and predicates in Java 8
asked 1xmediumJava8Technical2019
Ans. Lambda expressions in Java 8 are concise implementations of functional interfaces, letting you pass behaviour as data, often to streams or collection methods. A Predicate is a standard functional interface that takes one value and returns a boolean, commonly used for filtering. Lambdas reduce boilerplate compared with anonymous classes.
Q. Print all palindromic substrings of a given string.
asked 1xmediumStringsTechnical2021
Ans. Expand around every possible centre and print each substring whenever the expansion characters match. Use each index as an odd-length centre and each gap as an even-length centre. No special data structure is needed unless storing results. The time complexity is O(n²) plus printing cost, with O(1) extra space.
Q. What is ThreadLocal? Provide a use case or example.
asked 1xmediumOOPTechnical2024
Ans. ThreadLocal is a Java mechanism that gives each thread its own independent copy of a variable. It is useful for per-thread context, such as storing a user ID, request ID, or database connection during request handling. The key point is to remove values when using thread pools to avoid memory leaks or stale data.
Q. How do you create and use custom exceptions in Java?
asked 1xmediumOOPTechnical2020
Ans. Create a custom exception by defining a class that extends Exception for a checked exception, or RuntimeException for an unchecked one. Add constructors that pass a message and optionally a cause to the superclass. Use throw to raise it and catch it where you can handle it meaningfully.
Q. How many squares are there on a standard chessboard?
asked 1xmediumLogical reasoningHR2014
Ans. There are 204 squares on a standard chessboard. Count every possible square size, not just the 64 small ones. An 8 by 8 board has 8² one-cell squares, 7² two-cell squares, and so on down to 1². So the total is 8² + 7² + ... + 1² = 204.
Q. Explain process synchronization in Operating Systems.
asked 1xmediumOperating systemsTechnical2020
Ans. Process synchronization is the coordination of concurrent processes so they access shared resources safely and in the correct order. The key idea is protecting critical sections, where shared data is read or modified. Operating systems use mechanisms such as locks, semaphores, monitors and condition variables to prevent race conditions and deadlocks.
Q. Provide a code example of the Factory Design Pattern.
asked 1xmediumOOPTechnical2024
Ans. A factory pattern example is a ShapeFactory with a createShape(type) method that returns a Circle, Square, or Triangle object based on the input. The approach hides object creation behind one method. A simple map from type name to class is the key data structure, giving average constant-time lookup.
Q. Detect a cycle in a linked list and explain the logic.
asked 1xmediumLinked listsTechnical2015
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 there is a cycle, the fast pointer will eventually meet the slow pointer. If the fast pointer reaches null, there is no cycle. Time is O(n), space is O(1).
Q. Write complex MySQL queries using joins and subqueries
asked 1xmediumSQLTechnical2020
Ans. Use joins to combine related tables, then use subqueries when you need filtering, aggregation, or comparison based on another result set. For example, join customers to orders, group by customer, and use a subquery to compare each customer’s spend with the average spend. Index join keys and filtered columns for performance.
Q. Write the syntax for a pointer to a function in C/C++.
asked 1xmediumOOPTechnical2016
Ans. Use the form return_type (*pointer_name)(parameter_type_list) for a pointer to a function in C or C++. The parentheses around *pointer_name are essential, because without them you declare a function returning a pointer, not a pointer to a function. It can then store the address of any matching function.
Q. Make 1000 using eight 8's by only using +, -, *, and /.
asked 1xmediumLogical reasoningTechnical2015
Ans. ((8 + 8) * 8 - 8 / 8) * 8 - 8 - 8 = 1000. First make 128 from (8 + 8) * 8. Subtract 1 using 8 / 8 to get 127. Multiply by 8 to get 1016, then subtract 16.
Q. What are database triggers and when should they be used?
asked 1xmediumDBMSTechnical2019
Ans. Database triggers are stored actions that run automatically when specific database events occur, such as insert, update, or delete. They should be used for rules that must always be enforced close to the data, such as auditing, maintaining derived values, or validation. Use them carefully, as hidden logic can make behaviour harder to trace.
Q. Explain Shell Sort and Counting Sort with time complexity
asked 1xmediumSortingTechnical2016
Ans. Shell Sort is an in-place comparison sort that improves insertion sort by sorting elements far apart using shrinking gaps, then finishing with gap 1. Its time depends on the gap sequence, commonly worst case O(n²), with O(1) space. Counting Sort counts occurrences of keys in a limited range k, runs in O(n + k) time and uses O(k) space.
Q. What is an offset in Kafka, and why is Kafka widely used?
asked 1xmediumDistributed systemsTechnical2024
Ans. An offset in Kafka is the sequential position of a message within a topic partition. Consumers store committed offsets to know what they have processed, which enables retry, replay and fault recovery. Kafka is widely used because it provides high-throughput, durable, scalable messaging for decoupled services and real-time data pipelines.
Q. Explain and implement a doubly linked list data structure.
asked 1xmediumLinked listsTechnical2014
Ans. A doubly linked list stores nodes where each node has a value, a pointer to the next node, and a pointer to the previous node. Implement it with head and tail references. Insertion or deletion at a known node is O(1), while searching by value or index is O(n). Update both neighbouring links carefully.
Q. How would you handle a hypothetical work-related situation?
asked 1xmediumSituationalHR2014
Ans. Choose a realistic situation close to the role, such as conflicting priorities, an unhappy customer, or a team disagreement. Explain the steps you would take: clarify facts, involve the right people, weigh risks, act calmly, and follow up. Interviewers listen for judgement, communication, ownership, and a practical approach under pressure.
Q. What is the difference between Future and CompletableFuture?
asked 1xmediumOOPTechnical2024
Ans. Future is a basic handle to an asynchronous result, while CompletableFuture is a richer Future that can be completed manually and composed with other asynchronous actions. Future mainly offers blocking get, cancellation, and status checks. CompletableFuture adds callbacks, chaining, combining tasks, exception handling, and non-blocking continuation-style programming.
Q. Difference between synchronized HashMap and ConcurrentHashMap
asked 1xmediumConcurrencyTechnical2019
Ans. A synchronised HashMap uses one lock around the whole map, while ConcurrentHashMap is designed for concurrent access with finer grained locking and lock-free reads. The key difference is scalability: synchronizedMap blocks most operations during each access, but ConcurrentHashMap allows multiple reads and updates to different buckets safely at the same time.
Q. Quantitative aptitude problems similar to R.S. Aggarwal level.
asked 1xmediumQuantitativeOnline test2014
Ans. Use formulas only after identifying the problem type: percentage, profit and loss, time and work, trains, averages, ratio, or interest. Convert words into equations, keep units consistent, and simplify before calculating. For speed, use approximation where options are far apart, and verify the answer by substituting it back into the question.
Q. Design a stack supporting push, pop, and FindMin() in O(1) time
asked 1xmediumStackTechnical2014
Ans. Use two stacks: one normal stack for all values and one min stack storing the current minimum. On push, also push to the min stack if the value is less than or equal to its top. On pop, if the popped value equals the min top, pop the min stack too. FindMin returns the min stack top.
Q. Using two ropes that burn unevenly, measure exactly 45 minutes.
asked 1xmediumLogical reasoningTechnical2016
Ans. Light the first rope at both ends and the second rope at one end at the same time. The first rope finishes after 30 minutes. Then light the other end of the second rope. It has 30 minutes of burn left, and burning from both ends halves that to 15 minutes. Total time is 45 minutes.
Q. Explain what an immutable class is in Java and how to create one
asked 1xmediumOOPTechnical2019
Ans. An immutable class in Java is a class whose objects cannot change state after construction. Create one by making the class final, making fields private and final, setting all values in the constructor, providing no setters, and using defensive copies for any mutable fields, both on input and when returning them.
Q. Using 8 sticks, form two squares and four right-angled triangles
asked 1xmediumLogical reasoningTechnical2014
Ans. Make two complete squares with four sticks each. Put one square on top of the other with the same centre, rotated about 45 degrees, so its sides cut across the first square. The two sets of four sticks are the two squares. At the four corners of either square, the intersecting sides enclose right-angled triangles.
Q. What is indexing in databases and how do composite indexes work?
asked 1xmediumDBMSTechnical2019
Ans. Indexing is a way for a database to find rows faster by keeping a separate ordered data structure, often a B-tree, over one or more columns. A composite index covers multiple columns in a fixed order, and is most useful when queries filter or sort by the leftmost columns of that order.
Q. How would you implement asynchronous programming in your application?
asked 1xmediumAsynchronous processingSystem design2024
Ans. I would use async I/O with async/await for request paths, and a message queue with worker processes for long-running background tasks. The key detail is to define clear ownership and failure handling: timeouts, retries, idempotency keys, and dead-letter queues so asynchronous work does not create hidden data loss or duplicate side effects.
Q. Describe your experience dealing with clients or difficult stakeholders
asked 1xmediumLeadershipManagerial2020
Ans. Pick a real situation where a client or stakeholder was unhappy, unclear, or resistant, and you improved the outcome. Emphasise listening, staying calm, clarifying needs, managing expectations, and agreeing next steps. Interviewers listen for professionalism, ownership, communication under pressure, and evidence that you protected the relationship while still delivering results.
Q. Describe a time when you received critical feedback and how you acted on it
asked 1xmediumConflict resolutionManagerial2020
Ans. Choose a real example where the feedback was specific, fair, and led to visible improvement. Emphasise that you listened without defensiveness, clarified expectations, changed your behaviour, and followed up. Interviewers listen for self-awareness, coachability, ownership, emotional maturity, and evidence that the feedback improved your performance or working relationships.
Q. How can you trace which microservice is taking the most time during a transaction?
asked 1xmediumDistributed systemsSystem design2024
Ans. Use distributed tracing to follow one transaction across services and compare span durations. Propagate a trace ID through every request, usually with OpenTelemetry headers, and record spans for each service call. In Jaeger, Zipkin, or a similar tool, inspect the trace waterfall to find the longest span on the critical path.
Q. Design and implement a microservice API based on a given problem statement using your own tech stack
asked 1xmediumMicroservicesTechnical2019
Ans. I would design a small REST service with clear resource endpoints, a relational database, and stateless application nodes behind a load balancer. I would start from the domain model, define request and response contracts, then implement validation, persistence, authentication, logging, metrics, tests, and OpenAPI documentation. The key detail is keeping business logic isolated from transport and storage.
Q. Explain ACID properties in DBMS.
asked 1xeasyDBMSTechnical2016
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.
Showing 60 of 199 questions. Ranked by how often the same question came back across interviews.