Q. Find the first and last positions of an element in a sorted array
asked 2xeasyBinary searchTechnical2021
Ans. Use two binary searches: one to find the first index where the target appears, and one to find the last index. For the first, move left when you find the target; for the last, move right. Return both indices, or -1, -1 if absent. Time complexity is O(log n), space is O(1).
Q. Detect a cycle in a linked list
asked 1xmediumLinked listsTechnical2020
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. Write SQL queries to analyze data.
asked 1xmediumSQLTechnical2020
Ans. I would use SELECT with filtering, joins, grouping, aggregates, and window functions to answer the analysis question. Typically I filter rows with WHERE, combine tables with JOIN, summarise with GROUP BY, and rank or compare rows with window functions. The key detail is checking grain, so aggregates are not accidentally duplicated.
Q. Detect a cycle in a directed graph.
asked 1xmediumGraphsTechnical2015
Ans. Use DFS with a recursion stack to detect a cycle in a directed graph. Mark each node as unvisited, visiting, or visited. During DFS, if you reach a node marked visiting, there is a cycle. If DFS finishes, mark it visited. This takes O(V + E) time and O(V) space.
Q. How is HashMap implemented in Java?
asked 1xmediumOOPTechnical2015
Ans. Java HashMap is implemented as an array of buckets, where each bucket stores entries containing a key, value, hash, and next reference. The key’s hash is spread and mapped to an index in the array. Collisions are handled by linked lists, or by red-black trees when a bucket becomes large. It resizes when the load factor threshold is exceeded.
Q. Clone a graph (deep copy of a graph)
asked 1xmediumGraphsManagerial2021
Ans. Clone the graph by traversing it with DFS or BFS and using a hash map from each original node to its copied node. For every visited node, create its clone if needed, then connect cloned neighbours. The hash map is essential to avoid infinite loops in cycles. Time and space are O(V + E).
Q. Reverse a linked list in groups of k
asked 1xmediumLinked listsManagerial2021
Ans. Reverse each block of K nodes by iterating through the list, reversing K links at a time, and connecting the previous block’s tail to the new head. Use three pointers for reversal and keep track of the previous group tail. If fewer than K nodes remain, usually leave them unchanged. Time is O(n), space is O(1).
Q. Design and implement your own HashMap
asked 1xmediumOOPTechnical2021
Ans. Implement it as an array of buckets, where each bucket holds key value entries, usually in a linked list or dynamic array for collisions. Compute hash(key), map it to an index, then search that bucket. put updates or appends, get searches, remove deletes. Resize and rehash when load factor grows. Average time is O(1), worst case O(n).
Q. Group a list of strings into anagrams.
asked 1xmediumStringsTechnical2021
Ans. Use a hash map where the key is a canonical form of each word and the value is the list of words with that form. For each string, sort its characters and use the sorted string as the key. Append the original string to that group. Time is O(n k log k), where k is word length.
Q. Find the intercept of a regression line.
asked 1xmediumStatisticsOnline test2023
Ans. The intercept of a regression line is c = ȳ − m x̄, where m is the slope, x̄ is the mean of x values, and ȳ is the mean of y values. For a line y = mx + c, it is the predicted value of y when x equals zero.
Q. Beautiful Numbers problem
asked 1xmediumArraysOnline test2021
Ans. Use digit DP to count beautiful numbers up to N, then answer a range by computing f(R) minus f(L minus 1). The DP state stores the current digit position, tight flag, and the property needed by the definition, such as digit mask or digit sum. Memoisation gives time proportional to digits times state count.
Q. Explain the diamond problem in inheritance.
asked 1xmediumOOPTechnical2016
Ans. Inheritance lets a class reuse and extend behaviour from another class, forming parent and child relationships. The Diamond Problem happens in multiple inheritance when a class inherits from two classes that both inherit from the same base, creating ambiguity about which base member is used. Languages handle it with virtual inheritance, interfaces, or method resolution rules.
Q. Explain the principle of Consistent Hashing
asked 1xmediumDistributed systemsSystem design2021
Ans. Consistent hashing maps both keys and servers onto the same circular hash space, then assigns each key to the first server found clockwise from its hash. Its main benefit is that when a server is added or removed, only nearby keys move, rather than redistributing almost all data. Virtual nodes improve balance across servers.
Q. Find itinerary from a given list of tickets
asked 1xmediumGraphsTechnical2021
Ans. Build a map from source to destination, then find the starting city as the source that never appears as a destination. From that start, repeatedly follow the map to print the route. The key detail is using a reverse destination set or map to identify the only valid start. Time complexity is O(n).
Q. Count all palindromic substrings in a string
asked 1xmediumStringsTechnical2021
Ans. Count them by expanding around every possible centre and adding one for each successful expansion. Each character is an odd-length centre, and each gap between characters is an even-length centre. For each centre, move left and right while characters match. This uses constant extra space and takes O(n²) time.
Q. Detect a loop in a linked list and remove it
asked 1xmediumLinked listsTechnical2015
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. Find the length of the loop in a linked list
asked 1xmediumLinked listsTechnical2020
Ans. Use Floyd’s slow and fast pointer method to detect the loop, then count its length by keeping one pointer fixed at the meeting node and moving another around the cycle until it returns. Increment a counter on each move. This uses constant extra space and runs in O(n) time.
Q. What new features would you add to Instagram?
asked 1xmediumProduct designHR2023
Ans. I would add collaborative interest spaces, stronger content controls, and better creator analytics. The most important feature is user-controlled ranking: let people tune feeds by friends, topics, recency, or recommendations, with clear explanations for why posts appear. This improves trust, retention, and safety without changing Instagram’s core sharing experience.
Q. Find the first node of a loop in a linked list
asked 1xmediumLinked listsTechnical2020
Ans. Use Floyd’s slow and fast pointer method to detect the loop, then reset one pointer to the head and move both one step at a time; the node where they meet is the first node of the loop. This works in O(n) time and O(1) extra space.
Q. Explain the approach for solving a maze problem
asked 1xmediumAlgorithmsTechnical2020
Ans. Model the maze as a graph where each open cell is a node and moves to neighbouring open cells are edges. Use BFS with a queue to find the shortest path, marking visited cells to avoid loops and storing parents to reconstruct the route. Time and space complexity are O(rows × columns).
Q. Explain the working of ConcurrentHashMap in Java
asked 1xmediumOOPTechnical2021
Ans. ConcurrentHashMap is a thread-safe hash table that allows multiple threads to read and update it without locking the whole map. In Java 8+, reads are mostly lock-free using volatile access, while updates use CAS and lock only the affected bin. This gives much better concurrency than synchronising a HashMap or using Hashtable.
Q. Merge K sorted linked lists into one sorted list
asked 1xmediumLinked listsManagerial2021
Ans. Use a min heap containing the current head of each non-empty list. Repeatedly remove the smallest node, append it to the result, and insert its next node if it exists. This preserves sorted order while only comparing k candidates at a time. Time complexity is O(N log k), with O(k) extra space.
Q. Reverse a linked list in groups of given size K.
asked 1xmediumLinked listsTechnical2021
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. SQL subqueries and query optimization techniques
asked 1xmediumSQLTechnical2021
Ans. SQL subqueries are queries nested inside another query, commonly used in WHERE, FROM, or SELECT clauses to filter, aggregate, or derive data. For optimisation, prefer indexed joins when suitable, avoid correlated subqueries on large datasets, select only needed columns, use EXISTS for existence checks, inspect execution plans, and ensure indexes match filter and join conditions.
Q. Convert an infix expression to postfix expression
asked 1xmediumStacksTechnical2020
Ans. Use a stack to convert infix to postfix by scanning the expression left to right and outputting operands immediately. Push opening brackets, pop until an opening bracket on closing brackets, and for operators pop higher or equal precedence operators before pushing the current one. Finally pop remaining operators. This runs in O(n) time.
Q. Explain hypothesis testing and its key components.
asked 1xmediumStatisticsOnline test2023
Ans. Hypothesis testing is a statistical method for deciding whether data provides enough evidence to reject a default assumption. The key components are the null hypothesis, alternative hypothesis, significance level, test statistic, p-value, and decision rule. The main idea is to quantify whether an observed effect is likely due to chance.
Q. Generate all possible subsets of a given set/array
asked 1xmediumBacktrackingOnline test2019
Ans. Use backtracking to build the power set by deciding for each element whether to include it or skip it. Store the current subset in a list, add a copy when a decision path is complete, then backtrack. There are 2^n subsets, and copying them gives O(n × 2^n) time and space.
Q. Write example programs demonstrating polymorphism.
asked 1xmediumOOPTechnical2016
Ans. Example programs include a Shape program where Circle and Rectangle override area, an Animal program where Dog and Cat override speak, and a Payment program where CardPayment and CashPayment implement pay. Use a list of the base type or interface and call the common method. Dynamic dispatch is typically constant time per call.
Q. Check whether a singly linked list is a palindrome.
asked 1xmediumLinked listsTechnical2021
Ans. Use two pointers to find the middle, reverse the second half of the list, then compare it node by node with the first half. If all values match, it is a palindrome. The key detail is reversing only the second half, giving O(n) time and O(1) extra space.
Q. Answer questions related to the normal distribution.
asked 1xmediumStatisticsOnline test2023
Ans. A normal distribution is a symmetric, bell-shaped probability distribution defined by its mean and standard deviation. The mean sets the centre, while the standard deviation controls the spread. In a standard normal distribution, the mean is 0 and the standard deviation is 1. Many natural measurements approximate it due to the central limit theorem.
Q. Find the k-th smallest element in an unsorted array.
asked 1xmediumSortingTechnical2021
Ans. Use Quickselect to find the k-th smallest element in an unsorted array. It partitions the array like Quicksort, then only recurses into the side that contains the answer. Its average time complexity is O(n) and space is O(1) if done in place, though worst case is O(n²).
Q. Implement vertical order traversal of a binary tree.
asked 1xmediumTreesTechnical2021
Ans. Use BFS with a queue storing each node and its column index, starting root at 0, left child at column minus 1 and right child at column plus 1. Append values to a map from column to list. Track minimum and maximum columns, then output lists in that range. Time is O(n), space is O(n).
Q. Explain JSP fundamentals and how JSP works with HTTP.
asked 1xmediumNetworkingManagerial2023
Ans. JSP is a server-side Java view technology that creates dynamic web pages by generating HTML in response to HTTP requests. A JSP file is translated into a servlet by the web container, compiled, then executed. It reads request data, uses session or application state, calls Java logic, and writes an HTTP response.
Q. Find the starting node of the cycle in a linked list.
asked 1xmediumLinked listsTechnical2023
Ans. Use Floyd’s slow and fast pointers to detect a cycle, then reset one pointer to the head and move both one step at a time. The node where they meet is the cycle start. This works because the distances align after the first meeting. It uses no extra data structure and runs in O(n) time.
Q. What is a virtual destructor and why is it important?
asked 1xmediumOOPTechnical2016
Ans. A virtual destructor is a base class destructor declared virtual so destruction is dispatched to the real derived type. It is important when deleting a derived object through a base class pointer, because it ensures the derived destructor runs first, then the base destructor, avoiding resource leaks and undefined behaviour.
Q. Explain the internal implementation of HashMap in Java
asked 1xmediumOOPSystem design2021
Ans. Java HashMap is implemented as an array of buckets, where each bucket stores key-value entries based on the key’s hash code. The hash is spread and mapped to an index in the array. Collisions are handled by linked lists, or red-black trees when a bucket grows large. It resizes when the load factor threshold is exceeded.
Q. How are virtual functions implemented by the compiler?
asked 1xmediumOOPTechnical2016
Ans. Virtual functions are usually implemented using a virtual table and a hidden pointer in each object. The compiler creates one table per polymorphic class, containing function pointers for its virtual methods. Each object stores a pointer to its class table, and a virtual call is compiled as an indirect call through that table.
Q. A coding problem similar to the Shared Interest problem
asked 1xmediumHashingTechnical2019
Ans. Group users by each interest, generate all user pairs within that group, and count how many interests each pair shares. Use a hash map keyed by the ordered pair to store counts, then scan for the highest count, breaking ties by largest product of user ids. Time is proportional to total generated pairs, worst case O(E plus U squared per interest group).
Q. Design a data structure to implement the 15-puzzle game
asked 1xmediumData structuresTechnical2016
Ans. Use a 4 by 4 integer matrix to store tile positions, with 0 representing the blank, plus two integers for the blank row and column. A move checks whether the target neighbour is within bounds, swaps it with 0, and updates the blank position. Each move is O(1), and rendering scans 16 cells.
Q. Explain correlation and covariance and how they differ.
asked 1xmediumStatisticsOnline test2023
Ans. Covariance measures whether two variables move together, while correlation measures both the direction and the strength of their linear relationship on a standard scale. Covariance can be positive, negative, or zero, but its size depends on the variables’ units. Correlation is unitless and always ranges from -1 to 1.
Q. Find the k-th largest element in an array using a heap.
asked 1xmediumHeapsTechnical2017
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 works because the heap keeps only the k largest seen so far, in O(n log k) time and O(k) space.
Q. Solve the problem 'Abandoned City' using binary search.
asked 1xmediumBinary searchOnline test2021
Ans. Sort the city positions and binary search the largest possible minimum distance between chosen locations. For a trial distance, greedily place at the leftmost position, then take the next position at least that far away. If enough locations are chosen, try larger; otherwise try smaller. Time is O(n log n plus n log range).
Q. Find the largest subarray with equal number of 0s and 1s
asked 1xmediumArraysTechnical2021
Ans. Convert each 0 to -1, then find the longest subarray with prefix sum zero. Keep a hash map from prefix sum to its first index. When the same prefix sum appears again, the elements between those indices have equal 0s and 1s. This takes O(n) time and O(n) space.
Q. Find the Longest Increasing Subsequence (LIS) in an array
asked 1xmediumDynamic programmingTechnical2025
Ans. Use the patience sorting approach: maintain an array where each position stores the smallest possible tail value for an increasing subsequence of that length. For each number, binary search the first tail greater than or equal to it and replace it. This gives the LIS length in O(n log n) time and O(n) space.
Q. Explain different types of errors in statistical modeling.
asked 1xmediumStatisticsOnline test2023
Ans. Statistical modelling errors include bias, variance, irreducible noise, measurement error, and hypothesis testing errors such as Type I and Type II errors. Bias is wrong assumptions, variance is sensitivity to data, and irreducible error is random noise. The key trade-off is balancing bias and variance to improve generalisation.
Q. Find the minimum number of swaps required to sort an array
asked 1xmediumSortingTechnical2021
Ans. The minimum swaps are found by decomposing the permutation from current positions to sorted positions into cycles. Pair each element with its original index, sort by value, then visit indices; a cycle of length k needs k minus 1 swaps. Sum this over all cycles. This takes O(n log n) time and O(n) space.
Q. How does Spring Boot solve problems that Spring could not?
asked 1xmediumFrameworksManagerial2021
Ans. Spring Boot removes much of the manual setup needed in traditional Spring applications. It provides auto-configuration, starter dependencies, embedded web servers, and sensible defaults, so developers can build runnable applications faster. The key difference is convention over configuration, while still allowing Spring’s full flexibility when custom behaviour is needed.
Q. Write a program to implement a stack using classes in C++.
asked 1xmediumStackTechnical2016
Ans. Implement a Stack class in C++ with a private array or vector to store elements and public methods push, pop, top, isEmpty and size. Keep an integer index for the current top. push adds at the top, pop removes from it, and top reads it. All main operations take O(1) time.
Q. Design a Sudoku game and explain the algorithm to solve it.
asked 1xmediumBacktrackingTechnical2016
Ans. Design the game with a 9 by 9 board, input validation, fixed starter cells, conflict highlighting, and a solver. Use backtracking to solve: find an empty cell, try digits 1 to 9 that are valid in its row, column, and box, then recurse. Track used digits with sets or bitmasks. Worst case is exponential.
Q. Find K closest elements to a given value in a sorted array.
asked 1xmediumBinary searchOnline test2021
Ans. Use binary search to find the left boundary of the best window of size K, then return that window. Search between 0 and n minus K, comparing distance from x to arr[mid] and arr[mid + K]. Move towards the closer side. This gives O(log(n-K) + K) time and O(1) extra space.
Q. Find the longest palindromic subsequence in a given string.
asked 1xmediumDynamic programmingTechnical2016
Ans. Use dynamic programming where dp[i][j] stores the length of the longest palindromic subsequence inside s[i..j]. If s[i] equals s[j], set it to 2 plus dp[i+1][j-1], otherwise take the maximum of excluding either end. Fill by increasing substring length. Time is O(n²), space is O(n²).
Q. Propose and justify new features that could be added to Instagram.
asked 1xmediumProduct thinkingHR2024
Ans. A strong answer should choose one clear user problem, such as creator trust, wellbeing, discovery, or safer messaging. Propose features linked to that problem, explain the target users, expected impact, trade-offs, and success metrics. Interviewers listen for product thinking, prioritisation, user empathy, and awareness of Instagram’s business model and community risks.
Q. Answer data interpretation questions based on given charts or numerical data.
asked 1xmediumProbabilityOnline test2015
Ans. Read the chart title, units, scale, and labels first, then identify exactly what the question asks. Extract only the needed values, calculate carefully using percentages, ratios, averages, differences, or totals, and compare options if given. Watch for traps such as rounded figures, different units, cumulative data, and changing base values.
Q. What is the biggest challenge you have faced while using your preferred programming language?
asked 1xmediumProblem solvingManagerial2023
Ans. Pick a real challenge that shows depth in your preferred language, such as debugging concurrency issues, managing memory, handling performance limits, or navigating weak typing. Emphasise how you diagnosed the problem, learned language-specific tools or patterns, and improved the outcome. Interviewers listen for resilience, technical judgement, and evidence that you learn from difficult work.
Q. Solve Einstein-style logic puzzles involving multiple constraints to deduce correct assignments.
asked 1xmediumLogical reasoningOnline test2015
Ans. Create a grid with all categories and options, then mark impossible and confirmed pairings as you read each clue. Translate comparative clues into positions or relationships, not guesses. After every mark, scan rows, columns, and related clues for consequences. Continue eliminating until each item has one consistent assignment.
Q. Simulate rolling a dice and generate a random number between 1 and 6 without using built-in random functions
asked 1xmediumLogical reasoningTechnical2021
Ans. You cannot generate true randomness from a deterministic program alone. You need an external random source, such as coin flips. Flip three fair coins to make a number from 0 to 7. If it is 0 to 5, return that value plus 1. If it is 6 or 7, retry.
Q. Solve real-life scenario problems and explain solutions using technical concepts such as DBMS or system interrupts
asked 1xmediumProblem solvingManagerial2025
Ans. Pick a concrete incident where you diagnosed a real problem, such as slow reports, failed transactions, or an unresponsive device. Emphasise the symptoms, evidence gathered, technical concept used, and trade-offs. For DBMS, mention indexing, locking, transactions, or backups. For interrupts, explain priority, handling, and impact. Interviewers listen for structured reasoning and practical judgement.
Q. Solve aptitude questions based on work and time.
asked 1xeasyWork and timeTechnical2020
Ans. Use work rate: if a person finishes a job in x days, their rate is 1/x per day. Add rates when people work together, subtract if someone undoes work. Total time is 1 divided by combined rate. For wages or efficiency, split reward or work in the ratio of rates.
Q. Solve basic logical reasoning questions that test clarity of understanding.
asked 1xeasyLogical reasoningTechnical2020
Ans. There is no single answer because no specific logical problem is given. I would first identify the facts, translate the wording into clear conditions, check each option against those conditions, and eliminate contradictions. If several answers still fit, the question is under-specified and needs more information before a valid conclusion can be drawn.
Q. You are in a room with three switches, each connected to a bulb in another room that you cannot see. All switches are initially off. How do you determine which switch controls which bulb?
asked 1xeasyLogical reasoningHR2023
Ans. Turn on switch 1 for a few minutes, then turn it off. Turn on switch 2 and leave switch 3 off. Go to the bulb room. The lit bulb is controlled by switch 2. The unlit but warm bulb is controlled by switch 1. The unlit and cold bulb is controlled by switch 3.
Showing 60 of 275 questions. Ranked by how often the same question came back across interviews.