Q. What is the difference between an abstract class and an interface in Java?
asked 2xeasyOOPTechnical2020
Ans. An abstract class is a partial base class, while an interface is mainly a contract a class agrees to implement. An abstract class can hold instance state, constructors, and concrete methods, but a class can extend only one. A class can implement multiple interfaces, which is useful for defining shared capabilities.
Q. Detect and remove a loop in a linked list
asked 1xmediumLinked listsTechnical2014
Ans. Use Floyd’s slow and fast pointer method to detect the loop, then remove it by finding the node where the cycle starts and setting the previous node’s next pointer to null. After slow and fast meet, move one pointer to head and advance both one step at a time. Time is O(n), space is O(1).
Q. How do you make a class immutable in Java?
asked 1xmediumOOPTechnical2020
Ans. Make a class immutable in Java by preventing its state from changing after construction. Declare the class final, make fields private and final, set all values in the constructor, provide no setters, and return defensive copies of mutable fields. The key detail is not exposing any mutable internal object directly.
Q. What is a JIT compiler? Explain how it works.
asked 1xmediumOperating systemsTechnical2021
Ans. A JIT compiler is a just in time compiler that translates bytecode or intermediate code into native machine code while a program is running. It usually starts by interpreting code, identifies frequently executed parts, compiles those to optimised native code, and reuses them to improve performance, while keeping runtime flexibility.
Q. Explain concepts of threads and multiprocessing
asked 1xmediumOperating systemsTechnical2014
Ans. Threads are lightweight execution paths within the same process, sharing memory and resources, while multiprocessing runs separate processes with independent memory spaces. Threads are cheaper to create and communicate easily, but need careful synchronisation. Multiprocessing is heavier, but offers better isolation and can use multiple CPU cores more effectively for CPU-bound work.
Q. Explain Dijkstra’s algorithm and its applications.
asked 1xmediumGraphsTechnical2021
Ans. Dijkstra’s algorithm finds the shortest paths from one source node to all other nodes in a weighted graph with non-negative edge weights. It repeatedly picks the unvisited node with the smallest known distance and relaxes its outgoing edges. Using a priority queue, it runs in O((V + E) log V). It is used in routing, maps and network optimisation.
Q. Explain the implementation of Linux directory structure
asked 1xmediumOperating systemsTechnical2014
Ans. Linux implements directories as special files that store mappings from file names to inode numbers in a single tree rooted at /. The inode holds metadata and pointers to data blocks, while the directory entry links a name to that inode. The VFS layer provides a common interface across filesystems and caches dentries for faster path lookup.
Q. How long will it take to climb a 30-feet wall? (Puzzle)
asked 1xmediumLogical reasoningTechnical2021
Ans. There is no unique answer without the climbing rate and any slipping rule. The method is to track progress until the climber reaches 30 feet, not just use net gain blindly. In the common version, climbing 3 feet by day and slipping 2 at night, it takes 28 days.
Q. Explain Doubly Linked List and its operations with code.
asked 1xmediumLinked listsTechnical2024
Ans. A doubly linked list is a linear structure where each node stores data, a previous pointer, and a next pointer. Implement it with a Node class and head, optionally tail. Insert or delete at known ends in O(1), delete a known node in O(1), search and traversal in O(n). Pointers must be updated carefully.
Q. Explain the concept of Threads and Multithreading in Java.
asked 1xmediumOOPTechnical2024
Ans. A thread in Java is a lightweight path of execution within a process, and multithreading means running multiple threads concurrently in the same program. Threads share memory, so they are useful for responsive applications and parallel work, but shared data must be protected using synchronisation, locks, or concurrent utilities to avoid race conditions.
Q. Explain real-time applications of different data structures.
asked 1xmediumData structuresManagerial2020
Ans. Arrays store fixed-size data like image pixels or lookup tables. Linked lists support dynamic playlists and undo history. Stacks handle function calls and browser back actions. Queues manage printer jobs and messaging systems. Hash tables power caches and dictionaries. Trees organise file systems and indexes. Graphs model maps, networks and social connections.
Q. How does blockchain ensure data confidentiality and integrity?
asked 1xmediumSecurityTechnical2020
Ans. Blockchain ensures integrity through cryptographic hashes, digital signatures and consensus, but confidentiality is not guaranteed by default. Each block hashes the previous block, so tampering changes the chain, and signatures prove who authorised transactions. Confidentiality requires extra measures such as encryption, permissioned access, private channels or zero-knowledge proofs.
Q. Explain abstract classes vs interfaces. Why do interfaces exist?
asked 1xmediumOOPManagerial2021
Ans. Abstract classes share common state and behaviour between related classes, while interfaces define a contract that any class can implement. An abstract class can have fields, constructors and implemented methods. Interfaces exist to describe capabilities independently of inheritance, allowing polymorphism across unrelated types and avoiding the limits of single class inheritance.
Q. How do you decide which data structure to use for a given problem?
asked 1xmediumData structuresTechnical2021
Ans. I choose a data structure by matching the operations the problem needs most often to the structure that performs them efficiently. The key detail is the trade-off between lookup, insertion, deletion, ordering, and memory use. For example, use arrays for indexing, hash tables for fast lookup, heaps for priority, and trees for ordered data.
Q. What is normalization in databases and what are its different types?
asked 1xmediumDBMSTechnical2024
Ans. Normalization is the process of organising database tables to reduce data redundancy and avoid update, insert, and delete anomalies. The main types are 1NF, 2NF, 3NF, BCNF, 4NF, and 5NF. In practice, 3NF or BCNF is commonly used to keep data consistent while avoiding unnecessary complexity.
Q. Explain internal and external fragmentation in dynamic memory allocation.
asked 1xmediumOperating systemsTechnical2020
Ans. Internal fragmentation is wasted space inside an allocated block, while external fragmentation is free memory split into small non-contiguous holes. Internal fragmentation happens when allocators round requests up to fixed sizes. External fragmentation matters because total free memory may be enough, but no single free block is large enough for a request.
Q. Can a stack be implemented using a queue? Explain the principle of a stack.
asked 1xmediumStack queueTechnical2021
Ans. Yes, a stack can be implemented using one or two queues by rearranging queue operations to preserve last in, first out behaviour. A stack’s principle is LIFO: the last element pushed is the first one popped. With queues, this is usually done by rotating elements after each push.
Q. Why are trees needed? Explain tree traversals and why BSTs came into existence.
asked 1xmediumTreesTechnical2021
Ans. Trees are needed to represent hierarchical data and support efficient searching, insertion and deletion compared with linear structures. Traversals visit nodes in different orders: preorder processes root first, inorder left root right, postorder root last, and level order breadth first. BSTs came into existence to keep data ordered, enabling average O(log n) search.
Q. How does garbage collection work internally in Java? Why do memory leaks happen?
asked 1xmediumJavaManagerial2021
Ans. Java garbage collection finds objects no longer reachable from GC roots, such as thread stacks, static fields and JNI references, then reclaims their memory. Most collectors are generational, so short-lived objects are collected more often. Memory leaks happen when unused objects are still reachable, commonly through static collections, caches, listeners or unclosed resources.
Q. Explain the DOM and Virtual DOM, and describe how the Virtual DOM works in React.
asked 1xmediumOOPManagerial2021
Ans. The DOM is the browser’s live tree of HTML elements, while the Virtual DOM is React’s lightweight in-memory representation of that tree. When state or props change, React creates a new Virtual DOM tree, compares it with the previous one using reconciliation, calculates the minimal changes, and updates only the necessary parts of the real DOM.
Q. Explain the four pillars of OOP. Why is multiple inheritance not allowed in Java?
asked 1xmediumOOPManagerial2021
Ans. The four pillars are encapsulation, abstraction, inheritance, and polymorphism. Encapsulation hides state behind methods, abstraction exposes only essential behaviour, inheritance reuses and extends existing classes, and polymorphism lets one interface have different implementations. Java disallows multiple inheritance of classes mainly to avoid ambiguity, such as the diamond problem, but supports multiple interfaces.
Q. Is Java and C++ truly object-oriented? How does Java handle primitive data types?
asked 1xmediumOOPTechnical2020
Ans. Java and C++ are not purely object-oriented, because both allow features outside the object model. C++ supports procedural and generic programming, and Java has primitive types that are not objects. Java handles primitives like int, boolean and double as value types, with wrapper classes and autoboxing when objects are needed.
Q. Identify the pattern in a given mathematical series and write code to generate it.
asked 1xmediumLogical reasoningTechnical2020
Ans. Look at the differences between terms first, then ratios, then alternating patterns, powers, squares, cubes, primes, or Fibonacci-like sums. Once the rule is clear, store the first required values and generate each next term using that rule in a loop. Handle edge cases such as zero or one term.
Q. A puzzle related to choosing between heaven and hell based on truth-tellers and liars.
asked 1xmediumLogical reasoningManagerial2021
Ans. Ask either guard, “Which door would the other guard say leads to heaven?” Then choose the opposite door. If you ask the truth-teller, he truthfully reports the liar’s false answer. If you ask the liar, he lies about the truth-teller’s correct answer. In both cases, the indicated door is hell.
Q. Perform level order and spiral order traversal of a binary tree and analyze complexity
asked 1xmediumTreesTechnical2014
Ans. Level order traversal uses a queue to visit nodes breadth first, left to right at each level. Spiral order is similar, but alternates direction on each level, commonly using a deque or two stacks. Both visit every node once, so time complexity is O(n). Extra space is O(w), worst case O(n).
Q. Explain pointers and memory allocation for pointers. Why were pointers removed in Java?
asked 1xmediumMemory managementTechnical2020
Ans. A pointer is a variable that stores the memory address of another value. Memory is allocated both for the pointer variable itself and, separately, for the object it points to, often on the heap. Java removed raw pointers to improve safety, avoid pointer arithmetic, dangling references and memory corruption, and support garbage collection.
Q. Write SQL queries using joins, subqueries, GROUP BY, and HAVING clauses on given tables.
asked 1xmediumSQLTechnical2020
Ans. Use joins to combine related tables on key columns, subqueries to filter or derive intermediate results, GROUP BY to aggregate rows, and HAVING to filter aggregated groups. The key detail is choosing the correct join type and grouping column. Performance depends on indexes and plan choice, often dominated by join and sort or hash aggregation costs.
Q. Do graphs have a defined structure? Give real-life examples and explain graph traversals.
asked 1xmediumGraphsTechnical2021
Ans. Yes, a graph is a defined structure made of vertices, or nodes, connected by edges, which may be directed, undirected, weighted, or unweighted. Real examples include road networks, social networks, web links, and dependency graphs. Traversal means visiting nodes systematically, commonly using BFS with a queue or DFS with a stack or recursion.
Q. Can binary search be performed on a linked list? Explain how linked lists work internally.
asked 1xmediumLinked listsTechnical2021
Ans. Binary search can be performed on a linked list only in theory, but it is inefficient because there is no direct access to the middle element. A linked list stores data in separate nodes, each containing a value and a pointer to the next node, so reaching any position requires walking from node to node.
Q. Describe a situation related to teamwork or management and explain how you would handle it.
asked 1xmediumTeamworkManagerial2020
Ans. Choose a real situation where teamwork was under pressure, such as unclear ownership, conflict, missed deadlines, or a new team member needing support. Emphasise your specific actions, how you listened, aligned people, and kept the goal on track. Interviewers listen for collaboration, judgement, accountability, communication, and a calm, constructive approach.
Q. Given a triangular number pattern, identify positions and relationships within the sequence
asked 1xmediumLogical reasoningTechnical2014
Ans. Map each row and position to triangular numbers: 1, 3, 6, 10, 15, and so on. Find the row by locating between consecutive triangular totals. Then count across the row to get the position. Check whether entries follow simple differences, sums, products, or mirrored positions before choosing the relationship.
Q. Which data structure is best suited to implement a dictionary and what are its pros and cons?
asked 1xmediumData structuresTechnical2014
Ans. A hash table is usually best suited to implement a dictionary. It gives average constant time lookup, insertion and deletion by hashing keys to array positions. Its main drawbacks are extra memory use, collision handling, no natural ordering, and worst case linear time if many keys collide.
Q. Find the minimum number of increment operations required to make all elements of an array equal.
asked 1xmediumArraysOnline test2020
Ans. The minimum operations are the sum of differences between the maximum element and every other element. Since only increments are allowed, all values must be raised to the current maximum, never lowered. Find the maximum, then add max minus each element. This uses constant extra space and runs in O(n).
Q. Explain OOP concepts in Java including encapsulation, abstraction, inheritance, and polymorphism.
asked 1xmediumOOPTechnical2020
Ans. OOP in Java organises code around objects that combine data and behaviour. Encapsulation hides state using private fields and exposes controlled access through methods. Abstraction shows essential behaviour through interfaces or abstract classes. Inheritance lets a class reuse and extend another class. Polymorphism lets the same method call behave differently based on the actual object type.
Q. In C++, given a map<stud_id, cgpa>, delete all students whose cgpa < 5 without using extra space.
asked 1xmediumMapsTechnical2021
Ans. Iterate through the map and erase entries in place when the cgpa is less than 5. Use an iterator, and after erasing, assign it to the iterator returned by erase so you do not use an invalid iterator. This uses no extra space and runs in O(n) time for scanning the map.
Q. Explain the greedy approach used in the candy store problem and analyze its time and space complexity.
asked 1xmediumGreedyTechnical2020
Ans. Sort the candy prices and use two pointers greedily: for minimum cost, buy the cheapest remaining candy and take the k costliest remaining candies free; for maximum cost, buy the costliest remaining candy and take the k cheapest free. Sorting dominates the time complexity, O(n log n). Extra space is O(1) if sorting in place.
Q. Given a bitonic array, execute logic to produce the desired output and explain approach and complexity.
asked 1xmediumArraysTechnical2021
Ans. Find the peak using binary search, because a bitonic array first increases and then decreases. Compare mid with mid plus one to decide which side contains the peak. After that, handle the two halves separately if needed, such as binary searching increasing and decreasing parts. Time is O(log n), space is O(1).
Q. Explain encapsulation, abstraction, inheritance, method overloading, and method overriding with examples.
asked 1xmediumOOPTechnical2020
Ans. Encapsulation hides data inside a class, abstraction exposes only needed behaviour, inheritance reuses behaviour from a parent class, overloading uses the same method name with different parameters, and overriding replaces parent behaviour in a child. For example, a BankAccount hides balance, Vehicle has Car as a child, and Car overrides start.
Q. Explain the difference between Tree and Trie data structures and implement a Trie with real-time examples
asked 1xmediumData structuresTechnical2014
Ans. A tree is a general hierarchical structure, while a trie is a specialised tree for storing strings by shared prefixes. Implement a trie with nodes holding children by character and an end-of-word flag. Insert and search character by character in O(L) time. Examples include autocomplete, spell checkers, IP routing and dictionary lookup.
Q. Find the maximum number of meetings that can be accommodated in one meeting room given start and end times.
asked 1xmediumGreedyOnline test2020
Ans. Sort the meetings by their end time and greedily pick each meeting whose start time is at or after the end time of the last selected meeting. This maximises the count because finishing earliest leaves the most room for later meetings. Use an array of pairs. Time complexity is O(n log n).
Q. Write an SQL query to display student roll number along with faculty number given student and faculty tables.
asked 1xmediumSQLTechnical2024
Ans. Use an INNER JOIN to select the student roll number from the student table and the faculty number from the faculty table. Join the tables on the common faculty identifier, such as faculty_id. With indexes on the join columns, this is efficient; without indexes, it may require scanning both tables.
Q. Explain heap, stack, and code memory architecture in C++ and whether stack overflow can overwrite heap memory.
asked 1xmediumMemory managementTechnical2020
Ans. C++ programs typically have code memory for instructions, static storage for globals, heap for dynamic allocation, and stack for function calls and local automatic variables. Heap and stack are separate regions managed differently. A stack overflow usually hits a guard page and crashes; it normally does not overwrite heap memory, except on unprotected systems.
Q. Print the reverse of a singly linked list in O(n) time without using extra space and without modifying the list.
asked 1xmediumLinked listsTechnical2021
Ans. It cannot be done for a general singly linked list with all three constraints. To print in reverse you must remember previous nodes, which needs O(n) stack or explicit storage, or you must reverse the links and restore them, which modifies the list, or repeatedly scan from the head, which takes O(n²).
Q. Given an array of integers and a target sum t, count the number of triplets whose sum is less than or equal to t.
asked 1xmediumArraysOnline test2024
Ans. Sort the array, then count triplets using a fixed first element and two pointers for the remaining two elements. For each i, set left to i + 1 and right to n - 1. If arr[i] + arr[left] + arr[right] is less than or equal to t, then all choices from left + 1 to right also work, so add right - left and move left. Otherwise move right. Time complexity is O(n²).
Q. Implement multiple inheritance in Java using interfaces and demonstrate method overriding and method overloading.
asked 1xmediumOOPTechnical2020
Ans. Use a Java class that implements two or more interfaces, then override their declared methods in the class. If two interfaces provide the same default method, the class must explicitly override it to resolve ambiguity. Demonstrate overloading by adding methods with the same name but different parameter lists. No special data structure is needed; calls are constant time.
Q. Given prices of candies in a shop and an offer scheme, find the minimum and maximum amount needed to buy all candies.
asked 1xmediumGreedyOnline test2020
Ans. Sort the candy prices, then compute minimum by buying the cheapest remaining candy and taking the K costliest remaining candies for free. Compute maximum by buying the costliest remaining candy and taking the K cheapest remaining candies for free. Use two pointers on the sorted array. Time complexity is O(n log n), space is O(1) apart from sorting.
Q. Given meeting start and end times, find the minimum number of meeting rooms (or halls) required so that no meetings overlap.
asked 1xmediumArraysOnline test2020
Ans. Sort all start times and end times separately, then scan them to find the maximum number of meetings happening at once. Use two pointers: if the next start is before the earliest end, need another room; otherwise free one room. Track the maximum rooms used. Time complexity is O(n log n).
Q. You are given 3 buckets of capacities 4, 5, and 13 liters. How can you measure exactly 7 liters of water using these buckets?
asked 1xmediumLogical reasoningManagerial2021
Ans. Fill the 13 litre bucket. Pour from it into the 5 litre bucket and empty the 5 litre bucket. Repeat this once more. The 13 litre bucket now has 3 litres left. Fill the 4 litre bucket and pour it into the 13 litre bucket. It now contains exactly 7 litres.
Q. Given two unsorted arrays A and B, find the count of distinct pairs whose sum equals X. Explain the optimized approach and code it.
asked 1xmediumHashingTechnical2020
Ans. Use hashing: store all distinct values of B in a set, then iterate over distinct values of A and count when X minus the current value exists in B’s set. This counts each value pair once, even with duplicates in input. Time complexity is O(n + m), with O(n + m) extra space.
Q. Given n, generate a concentric square matrix pattern and then modify the logic to generate the inverse pattern (example shown for n=3)
asked 1xmediumArraysTechnical2014
Ans. Create a matrix of size 2n−1 and set each cell from its distance to the nearest border. For the normal pattern, value is n minus that minimum distance. For the inverse pattern, value is 1 plus that minimum distance. Use a 2D array, fill every cell once, so time is O(n²).
Q. Given two unsorted arrays A and B of distinct elements, find all distinct pairs (a, b) such that a + b = X and return the count of such pairs.
asked 1xmediumHashingOnline test2020
Ans. Put all elements of B into a hash set, then scan A and check whether X minus the current element exists in that set. Each successful lookup gives one distinct pair, so increment the count. This avoids sorting and handles unsorted input in O(n + m) time with O(m) extra space.
Q. How do you handle work pressure? How do you plan before starting challenging tasks? Describe a situation where you learned from your mistakes.
asked 1xmediumConflict resolutionManagerial2021
Ans. Choose a real, recent situation with high stakes, tight deadlines, or uncertainty. Emphasise staying calm, breaking work into priorities, clarifying expectations, planning milestones, and communicating early. For the mistake, show ownership, what you changed, and measurable improvement. Interviewers listen for resilience, judgement, structure, accountability, and learning without blaming others.
Q. Given an integer array and a value k, find the minimum element in each subarray of size k and then print the maximum among those minimum values.
asked 1xmediumArraysTechnical2020
Ans. Use a monotonic increasing deque to get each window minimum, and keep the maximum of those minima as you slide the window. Store indices in the deque, remove indices outside the current window, and remove larger trailing elements before inserting the new one. This gives O(n) time and O(k) space.
Q. Given a binary string containing wildcard characters '?', generate all possible strings by replacing each '?' with both 0 and 1. Example: Input 0?1?
asked 1xmediumStringsTechnical2014
Ans. Use backtracking to scan the string and branch whenever a ? is found, replacing it once with 0 and once with 1. For 0?1?, the results are 0010, 0011, 0110, 0111. Store the current characters in a mutable array. Time complexity is O(2^k * n), where k is the number of wildcards.
Q. Given an array of integers and a value k, find all triplets such that the product of two elements equals k and the third element equals k. Example: Array {2,3,7,6,8,9}, k=6
asked 1xmediumArraysTechnical2014
Ans. The triplet is (2, 3, 6), because 2 multiplied by 3 equals k, and the third element is also k. Use a hash set to store array values, first check that k exists, then for each element x check whether k is divisible by x and k / x exists. Time complexity is O(n).
Q. Encode a string by mapping each character to its alphabetical index (a=1, b=2, ...). If a character repeats consecutively, append its count in parentheses after the encoded value.
asked 1xmediumStringsOnline test2024
Ans. Scan the string once, group consecutive equal characters, convert each character to its alphabet position, and append the count in parentheses only when the group length is greater than one. Use a string builder to avoid repeated string copying. The time complexity is O(n), with O(n) space for the output.
Q. Given an array of n positive integers, find the minimum number of iterations to make all elements equal. In each iteration, all elements except the maximum element are reduced by 1.
asked 1xmediumArraysOnline test2020
Ans. The minimum is 0 if the array is already equal; otherwise it is impossible, so there is no finite number of iterations. The key point is that the current maximum never decreases, while every smaller element is reduced further, so the gap to the maximum can only stay positive or grow.
Q. Predict the output of pointer and array operations in C++ for code involving array increment, pointer increment, and dereferencing (e.g., cout<<a++; cout<<p++; cout<<*a++; cout<<*p++;).
asked 1xmediumOOPTechnical2021
Ans. a++ and *a++ do not compile, because an array name is not a modifiable pointer. p++ compiles and prints the old pointer address, then advances p to the next element. *p++ compiles and prints the value currently pointed to, then advances p, because postfix ++ has higher precedence than dereference.
Q. Find the maximum number of distinct pairs in an array such that the sum of each pair equals a given target. Each pair should be counted only once even if multiple index combinations exist.
asked 1xmediumArraysOnline test2020
Ans. Use a hash set to record values seen, and another set to store each valid pair in normalised order. For each number x, check target minus x; if it was seen, add min(x, y), max(x, y) to the pair set. The answer is the pair set size. Time is O(n).
Q. Describe a challenging situation you faced in a project and how you handled it.
asked 1xeasyProblem solvingHR2021
Ans. Choose a real project challenge with clear stakes, such as a missed deadline, technical risk, conflict, or changing requirements. Emphasise your specific actions, judgement, communication, and ownership, not just the problem. Interviewers listen for structured thinking, calm under pressure, collaboration, learning, and a measurable improvement or outcome.
Showing 60 of 115 questions. Ranked by how often the same question came back across interviews.