Top 127 DSA Interview Questions (2026)

Data Structures and Algorithms (DSA) form the foundation of technical interviews at top product companies like Google, Amazon, Microsoft, and Flipkart. Interviewers use DSA problems to assess your problem-solving approach, time and space complexity reasoning, and coding efficiency. This list covers the most frequently asked DSA interview questions across arrays, linked lists, trees, graphs, and dynamic programming.

16 Easy
86 Medium
25 Hard
Updated July 2026
01

How do you find a pair of elements with a given sum in an array?

Interviewers ask this to assess a candidate's ability to optimize space and time complexity beyond brute force solutions. They want to see if you can recognize patterns where a hash map reduces lookup time from O(n) to O(1). This problem also evaluates your understanding of trade-offs between using extra memory for speed versus keeping space complexity low. A strong answer demonstrates clear communication of algorithmic choices and edge case handling.

Easy
02

How would you find the element that appears exactly once in an array?

Interviewers use this to quickly gauge a candidate's familiarity with XOR operations or hash maps. The XOR approach is particularly favored for its O(1) space complexity, demonstrating deep understanding of low-level bit manipulation properties. It separates candidates who memorize solutions from those who understand underlying mechanisms.

Easy
Microsoft
03

What is the best way to buy and sell stock for maximum profit?

This question is designed to test a candidate's grasp of greedy strategies and dynamic programming concepts. Interviewers look for the ability to track the minimum price seen so far while calculating potential profits in a single pass. It reveals how well you can simplify complex financial scenarios into efficient code without unnecessary loops.

Easy
04

How do you find an element that appears exactly once in an array?

Interviewers look for proficiency in bitwise XOR operations which offer O(n) time and O(1) space solutions. It shows if you can think beyond standard library functions to write highly efficient code.

Easy
Microsoft
05

Can you explain how to reverse a string efficiently?

This question is designed to test a candidate's ability to manipulate strings in-place or with minimal extra space. It reveals their understanding of memory management and pointer arithmetic concepts, even in high-level languages. Interviewers look for candidates who can optimize solutions beyond simple library calls, demonstrating deeper algorithmic thinking.

Easy
Infosys
06

What strategy removes duplicates from a sorted array efficiently?

Interviewers use this to test the candidate's ability to optimize space usage by modifying arrays in-place. It checks if they understand the properties of sorted arrays and can leverage them for efficient algorithms. The question also evaluates attention to detail regarding return values and array lengths.

Easy
Infosys
07

Explain the Fibonacci series and its generation.

The Fibonacci series is a classic programming problem used to test recursion, iteration, and understanding of sequences. It is a standard interview question for entry-level engineers.

Easy
Infosys
08

How do you find the element that appears exactly once in an array?

Interviewers use this to check if candidates know the XOR property where a ^ a = 0 and a ^ 0 = a. It demonstrates whether they can solve a problem in O(n) time with O(1) space instead of using hash maps or sorting. This shows efficiency in resource usage and familiarity with fundamental bitwise operators which are crucial for systems programming.

Easy
Microsoft
09

Explain OOP concepts with practical examples.

OOP is a foundational paradigm in modern software development. Interviewers ask this to check your grasp of core programming concepts and your ability to apply them in real-world scenarios. It demonstrates whether you can write modular, reusable, and maintainable code, which is essential for any developer role.

Easy
TCS
10

What is the optimal approach to solve the Two Sum problem?

The Two Sum problem is a fundamental interview question to assess data structure knowledge. Interviewers want to see if the candidate knows how to use a hash map to achieve O(n) time complexity instead of O(n^2). It also checks their ability to handle edge cases and return indices correctly.

Easy
Infosys
11

What is the most efficient way to reverse a string?

Candidates are asked this to gauge their understanding of string immutability in languages like Java or Python. Interviewers look for knowledge of in-place reversal techniques to minimize space usage. It also tests familiarity with common string library functions versus manual implementation strategies.

Easy
Infosys
12

How do you check if an array is sorted in a single pass?

Interviewers ask this to assess fundamental coding skills and the ability to write clean, efficient loops. They want to see if the candidate understands edge cases like empty arrays or single-element arrays. Additionally, it evaluates whether the candidate can optimize for O(n) time complexity without unnecessary nested iterations. This serves as a quick filter for logical thinking and code correctness.

Easy
Infosys
13

Can you explain how to reverse a string in-place efficiently?

Interviewers use this problem to test a candidate's grasp of memory efficiency and pointer manipulation. Reversing a string is a common task where beginners often allocate new memory unnecessarily. By asking for an in-place solution, they evaluate if the candidate can optimize space complexity to O(1) while maintaining linear time performance.

Easy
Infosys
14

What is the best strategy to buy and sell stock for maximum profit?

This question is fundamental for assessing algorithmic thinking and optimization skills. Interviewers look for candidates who can identify the pattern of buying low and selling high without looking ahead. It tests the ability to maintain state variables like minimum price and maximum profit while traversing data. The simplicity of the problem often hides the need for precise logic to avoid off-by-one errors.

Easy
15

How would you reverse a string without using built-in functions?

Interviewers ask this to verify that candidates understand string internals and can implement algorithms without relying on library shortcuts. It demonstrates mastery of basic data structures and control flow. The question also helps gauge the candidate's ability to think about space efficiency and character swapping logic.

Easy
Infosys
16

What is Kadane's Algorithm and how does it solve the maximum subarray problem?

Kadane's algorithm is a staple interview question because it demonstrates mastery of dynamic programming concepts. Interviewers want to see if you can identify overlapping subproblems and make optimal local choices. It also tests your ability to explain complex logic simply and handle negative numbers correctly.

Easy
Microsoft
17

How do you flatten a linked list with random pointers?

It challenges candidates to think about modifying structures in-place without losing references. Interviewers evaluate recursive vs iterative approaches and memory management skills. It also tests robustness against circular references or complex branching.

Hard
Goldman Sachs
18

How do you trap rain water given an elevation map?

This complex problem evaluates advanced problem-solving skills and the ability to visualize spatial relationships. Interviewers look for candidates who can break down the problem into finding the left and right boundaries for each bar. It demonstrates mastery of two-pointer techniques or stack-based monotonic structures.

Hard
19

What is the Egg Dropping Puzzle and how do you solve it?

Interviewers use this to test advanced DP and optimization techniques. They want to see if you can reduce the state space or use mathematical insights. It demonstrates complex problem solving.

Hard
20

How do you count ongoing events for multiple query times?

Interviewers ask this to evaluate a candidate's ability to optimize solutions beyond brute force methods. They want to see if you can identify patterns in interval data, such as sorting start and end times separately. The core evaluation focuses on time complexity reduction, specifically moving from O(N*Q) to O((N+Q)logN) or better using binary search or sweep line algorithms. This demonstrates deep understanding of data structures and algorithmic thinking required for high-scale systems.

Hard
Google
21

Can you explain the 0-1 Knapsack problem and its solution?

This is a quintessential dynamic programming problem that tests optimization skills. Interviewers assess your ability to define states and transitions. It also evaluates your understanding of NP-hard problems and approximation strategies.

Hard
Infosys
22

What is the Bridges in a Graph problem and how do you solve it?

Interviewers use this to test graph theory depth. They want to see if you can implement articulation points and bridges using discovery times and low-link values. It demonstrates advanced graph algorithms.

Hard
23

How can you count strings formed using a, b, and c under constraints?

Interviewers use this to test advanced dynamic programming skills and the ability to model complex constraints mathematically. They want to see if you can break down a counting problem into overlapping subproblems. It also checks optimization skills for large input sizes.

Hard
Google
24

How do you find the Median from a Data Stream efficiently?

Interviewers ask this to test dynamic median maintenance. They want to see if you can use two heaps to balance the data. It demonstrates streaming algorithm skills.

Hard
25

How do you implement the Trapping Rain Water problem efficiently?

Interviewers ask this to test complex problem-solving skills involving boundary conditions and cumulative calculations. They want to see if you can determine the water level at each index based on the maximum heights to its left and right. It demonstrates mastery of multi-pass algorithms or stack-based solutions.

Hard
26

How do you count inversions in an array efficiently?

Interviewers ask this to test advanced sorting and counting techniques. They want to see if you can modify Merge Sort to count inversions during the merge step. It demonstrates algorithmic modification.

Hard
27

Can you explain the Trapping Rain Water problem and its solution?

This is a challenging problem that evaluates advanced problem-solving skills and mathematical intuition. Interviewers assess whether you can derive the water level at each position based on the maximum height to its left and right. It tests the ability to optimize a brute-force O(n^2) solution to O(n). The question also gauges how you handle complex constraints and visualize the problem geometrically.

Hard
28

What is the optimal path to maximize collected rocks in a grid?

This question tests a candidate's proficiency in dynamic programming, a critical skill for optimizing resource allocation and pathfinding problems in finance and tech. Interviewers want to see if the candidate can break down a complex problem into overlapping subproblems and define a clear state transition equation. It also evaluates their ability to reconstruct the actual path taken, not just the maximum value.

Hard
Goldman Sachs
29

What is the Trapping Rain Water problem and how to solve it?

It tests spatial reasoning and array manipulation skills. Interviewers ask this to see if you can derive optimal solutions for geometric problems. It is a favorite in competitive programming.

Hard
Flipkart
30

How do you solve the Matrix Chain Multiplication problem efficiently?

Interviewers ask this to assess deep knowledge of dynamic programming techniques. They want to see if you can identify overlapping subproblems and define a recurrence relation correctly. The complexity of deriving the solution helps distinguish senior engineers from juniors who might only know basic recursion.

Hard
Microsoft
31

What is the optimal dynamic programming approach to maximize rocks collected in a grid?

This question tests advanced problem-solving skills, specifically the application of dynamic programming to grid-based optimization problems. It evaluates whether the candidate can define appropriate state transitions and handle dependencies between cells. Additionally, reconstructing the actual path from the DP table demonstrates a deeper understanding beyond just computing the maximum value.

Hard
Goldman Sachs
32

How do you count ongoing events for specific query times?

Interviewers ask this to evaluate a candidate's ability to solve interval-based problems efficiently. They look for understanding of brute-force versus optimized approaches, such as using sorting and binary search. The problem assesses how well a candidate can handle time complexity constraints and data structure manipulation under pressure.

Hard
Google
33

What is the optimal path to maximize rocks collected in a grid?

This question evaluates a candidate's ability to apply dynamic programming to optimize a pathfinding problem. It tests the skill of defining states, transitions, and base cases in a matrix. Interviewers look for the ability to break down a complex problem into overlapping subproblems and build up the solution iteratively. It also assesses spatial reasoning and the capacity to reconstruct the actual path taken, not just the maximum value.

Hard
Goldman Sachs
34

How do you implement a solution to find the longest common subsequence?

LCS is a classic problem that evaluates a candidate's ability to optimize recursive solutions using memoization. It tests logical thinking and proficiency in DP. Mastery here indicates readiness for complex algorithmic challenges in production code.

Hard
Flipkart
35

Explain the Merge K-Sorted Lists algorithm and its complexity.

Merging sorted streams is a common pattern in big data. Interviewers ask this to test your ability to optimize merge operations. It demonstrates mastery of advanced data structures.

Hard
Flipkart
36

How do you count strings formed under specific character constraints?

Interviewers use this to test advanced problem-solving skills involving counting principles and state transitions. It reveals whether a candidate can model complex constraints mathematically and implement them using dynamic programming. It also checks their ability to handle large numbers and modulo arithmetic if required.

Hard
Google
37

What is Assembly Line Scheduling and how do you solve it?

This problem tests complex DP state management and the ability to model real-world logistics scenarios. It is often used to differentiate senior candidates.

Hard
Amazon
38

What is the optimal dynamic programming approach for a grid path problem?

Grid problems are common in finance and tech interviews to test optimization skills. Interviewers want to see if you can break down a complex pathfinding problem into overlapping subproblems. They evaluate your ability to define states, derive recurrence relations, and reconstruct the solution path if required.

Hard
Goldman Sachs
39

How do you merge K sorted lists into one sorted list?

This question evaluates a candidate's ability to handle multiple data streams efficiently. Interviewers look for the use of a min-heap to always pick the smallest available element. It tests priority queue implementation and time complexity analysis for large datasets.

Hard
40

How do you calculate the edit distance between two strings?

Edit distance is widely used in spell checkers and DNA sequencing. Interviewers ask this to test complex DP table construction and understanding of insertion, deletion, and substitution costs.

Hard
Amazon
41

How do you implement Matrix Chain Multiplication using Dynamic Programming?

Interviewers ask this to assess a candidate's depth in algorithm design and optimization techniques. They want to see if you can identify the state space, define the recurrence relation correctly, and implement an efficient solution that minimizes scalar multiplications. This problem is a classic example used to distinguish candidates who understand theoretical concepts from those who can apply them practically under constraints.

Hard
Microsoft
42

Explain the concept of graph components in data structures?

Interviewers ask this to verify that candidates have a solid grasp of graph traversal algorithms like DFS and BFS. They want to ensure you can distinguish between undirected and directed graph properties. This knowledge is crucial for solving complex connectivity problems in real-world systems like social networks or routing protocols.

Medium
Microsoft
43

How do you find a triplet where a squared equals b squared plus c squared?

This question checks if you can optimize a brute-force O(N^3) solution to something more efficient like O(N^2). Interviewers look for your ability to transform mathematical conditions into algorithmic steps. They also evaluate your understanding of hashing or two-pointer techniques to reduce search space. It simulates scenarios where finding specific patterns in large datasets is crucial.

Medium
Amazon
44

How can you arrange buildings so each has a clear view of the sea?

This question checks your proficiency in array manipulation and optimization techniques. It requires recognizing patterns where a single pass or stack-based approach yields better performance than brute force. It highlights logical thinking in geometric or constraint-based problems.

Medium
Microsoft Corporation
45

How do you detect a cycle in a linked list efficiently?

Cycle detection is a critical skill for debugging and validating data structures. Interviewers look for knowledge of Floyd's Tortoise and Hare algorithm, which is the standard efficient solution. It tests your ability to work with slow and fast pointers to detect infinite loops without using extra memory. This demonstrates strong algorithmic fundamentals and awareness of memory efficiency.

Medium
46

Explain the stock span problem and its solution.

This problem tests your ability to use monotonic stacks to solve range queries efficiently. It is a common pattern in financial algorithms and time-series analysis.

Medium
Amazon
47

How do you implement the Jump Game to reach the end?

Interviewers ask this to test greedy strategy application. They want to see if you can track the maximum reachable index efficiently. It demonstrates single-pass logic.

Medium
48

Can you explain Kadane's Algorithm for maximum subarray sum?

Kadane's Algorithm is a fundamental concept in dynamic programming and is often used to filter candidates who understand state transitions. Interviewers ask this to see if you can derive an optimal solution from a naive recursive approach. It evaluates your ability to think about local versus global maximums and how to maintain state across iterations. Mastery of this algorithm indicates readiness for more complex DP problems.

Medium
Infosys
49

How can you find a subarray with a given sum efficiently?

Interviewers use this to gauge a candidate's grasp of fundamental array algorithms. They want to see if the candidate can distinguish between positive-only arrays (sliding window) and general arrays (hash map). It also evaluates their ability to handle non-negative constraints mentioned in the prompt.

Medium
Google
50

How does the Next Permutation algorithm work?

This tests your ability to manipulate arrays logically and handle edge cases in permutation generation.

Medium
Microsoft Corporation
51

Explain the concept of graph components in computer science?

Interviewers ask this to gauge your grasp of core data structures and algorithms. They want to see if you can define maximal sets of vertices where every pair is reachable. Understanding these concepts is crucial for solving complex pathfinding, network analysis, and dependency resolution problems often encountered at scale.

Medium
Microsoft Corporation
52

How do you find the K largest elements from a large file?

Interviewers ask this to assess how candidates manage memory constraints and process data streams. They want to see if you understand that standard sorting is too expensive for massive files. The focus is on using a min-heap to maintain only the top K elements, ensuring O(N log K) time complexity instead of O(N log N). This demonstrates practical algorithmic thinking for real-world big data scenarios common at Amazon.

Medium
Amazon
53

How would you implement Kadane's Algorithm for maximum subarray sum?

Kadane's Algorithm is a fundamental technique for solving subarray problems efficiently. Interviewers ask this to see if candidates can recognize patterns that allow for linear time solutions instead of exponential ones. It also tests their understanding of state management and greedy strategies within dynamic programming contexts.

Medium
Infosys
54

How can you arrange buildings to ensure clear sea views with optimal time complexity?

This problem tests your ability to optimize array processing problems using monotonic stacks or similar patterns. It checks if you can identify the pattern of 'clearing' obstacles (taller buildings) to solve a visibility constraint efficiently.

Medium
Microsoft Corporation
55

Prepare well for basic programming concepts especially OOP and DBMS

OOP and DBMS are foundational for almost all software development roles. Interviewers ask related questions to ensure you have a strong theoretical base before diving into complex coding problems. These concepts are critical for writing maintainable and efficient code.

Medium
TCS
56

What is the minimum number of meeting rooms required for overlapping meetings?

This problem tests your ability to work with intervals and prioritize events using heaps or sorting. It simulates real-world resource allocation scenarios where efficiency is key. Interviewers evaluate your skill in optimizing algorithms to handle time-based constraints and your ability to reduce complex scheduling problems to simpler computational steps.

Medium
Microsoft
57

How do you find a subarray with a specific sum efficiently?

Interviewers ask this to gauge familiarity with the sliding window pattern, which is crucial for subarray problems. They also want to see if the candidate understands why the non-negative constraint allows for an O(n) solution compared to O(n^2) or O(n log n) general cases.

Medium
Google
58

What is the best way to find the majority element in an array?

This question tests knowledge of voting algorithms and frequency counting. Interviewers want to see if you can solve it in O(n) time and O(1) space. It also checks your ability to verify the candidate count after the initial pass.

Medium
Infosys
59

What is the Lowest Common Ancestor in a Binary Search Tree?

This tests your understanding of BST properties (left < root < right) and tree traversal algorithms.

Medium
Amazon
60

What is the stock span problem and how do you solve it efficiently?

The stock span problem is a classic example of applying stacks to find the nearest greater element to the left. It demonstrates the candidate's ability to optimize a naive O(N^2) solution to O(N).

Medium
Amazon
61

How do you find the next greater element for each item in an array?

This is a standard interview question to test proficiency with stacks and the concept of finding the next greater element, a pattern recurring in many optimization problems.

Medium
Amazon
62

How do you solve the 0/1 Knapsack Problem using dynamic programming?

Interviewers ask this to test fundamental DP understanding. They want to see if you can define the state transition for including or excluding items. It demonstrates resource allocation logic.

Medium
63

How would you solve the Two Sum problem efficiently?

This question is a staple because it effectively differentiates candidates who know basic iteration from those who understand hash-based lookups. Interviewers evaluate your ability to optimize space-time trade-offs. It also tests logical reasoning when dealing with duplicate values and index management.

Medium
Infosys
64

How do you determine if a binary tree is height-balanced?

Balanced trees are fundamental to efficient database indexing and search algorithms used in financial systems. Interviewers want to verify that you understand recursion depth and subtree validation. They are looking for candidates who can write clean, recursive code without stack overflow risks.

Medium
Goldman Sachs
65

What is the Pacific Atlantic Water Flow problem and how do you solve it?

Interviewers use this to test reverse graph traversal. They want to see if you can start from the ocean and flow uphill. It demonstrates bidirectional thinking.

Medium
66

How do you implement a Trie data structure for prefix searching?

Interviewers ask this to evaluate data structure design skills and string handling capabilities. They want to see if you understand how Tries optimize prefix searches compared to hashing or linear scans. It demonstrates structural design and node management.

Medium
67

How do you calculate the sum of a tree where each node is the sum of its children?

Interviewers want to see if you can validate tree properties recursively. It checks your ability to aggregate data from subtrees. The problem also tests logical consistency in tree definitions.

Medium
Goldman Sachs
68

What is Circular Tour problem and how do you solve it?

This problem tests logical reasoning and greedy strategy application. Interviewers ask it to see if you can handle circular buffer problems efficiently. It is a classic coding challenge for technical rounds.

Medium
Flipkart
69

How do you find a pair with a given sum in an array?

Interviewers ask this to evaluate a candidate's ability to optimize space and time complexity. They want to see if you can move beyond the naive O(n^2) brute force solution. The question specifically probes knowledge of using auxiliary data structures like hash sets to achieve O(n) time complexity. It also assesses how well you handle edge cases such as duplicate elements or arrays with no valid pairs.

Medium
70

What are real-world applications of a doubly-linked list?

This tests deep understanding of data structures beyond just definition. Interviewers want to know if the candidate can identify scenarios where bidirectional traversal is advantageous. It demonstrates analytical thinking and the ability to map theoretical concepts to practical engineering problems.

Medium
Infosys
71

How do you find a subarray with a given sum efficiently?

This problem tests your familiarity with the sliding window technique, which is crucial for array problems involving sums or averages. It demonstrates your ability to reduce time complexity from O(n^2) to O(n) by maintaining a running sum and adjusting the window dynamically. Interviewers look for clean code and an explanation of why the non-negative constraint matters.

Medium
Google
72

How do you arrange buildings with a sea view using an optimal algorithm?

Building arrangement problems simulate real-world constraints like visibility and height limits. Interviewers assess your ability to iterate efficiently and maintain state variables. It checks if you can achieve O(n) time complexity rather than a brute-force O(n^2) solution.

Medium
Microsoft Corporation
73

How do you validate if a binary tree is a valid Binary Search Tree?

Interviewers ask this to test deep understanding of BST properties beyond simple comparisons. They want to see if you realize that a node must be within a valid range defined by its ancestors, not just its immediate parent. It demonstrates recursive thinking and constraint propagation.

Medium
74

Can you explain how to find a triplet where a squared equals b squared plus c squared?

This question evaluates your problem-solving skills and ability to transform a mathematical condition into an algorithmic solution. Interviewers look for candidates who can recognize patterns and optimize brute-force approaches using hashing or two-pointer techniques. It also tests your attention to detail regarding variations like sum equaling zero.

Medium
Amazon
75

What is the approach to find the longest palindromic substring?

This problem tests string processing skills and the ability to handle even and odd length palindromes. Interviewers look for an understanding of expanding around centers or dynamic programming states. It evaluates attention to detail in boundary conditions and character comparisons.

Medium
Infosys
76

How do you maximize profit in a single stock transaction scenario?

This is a standard problem to evaluate a candidate's ability to apply greedy strategies. Interviewers look for the insight that keeping track of the minimum price seen so far allows calculating potential profit in a single pass. It demonstrates logical reasoning and optimization skills.

Medium
Infosys
77

How do you detect a loop in a linked list and find its start node?

Interviewers use this problem to assess a candidate's mastery of pointer manipulation and fundamental graph traversal algorithms. Specifically, they look for knowledge of Floyd’s Cycle Detection Algorithm, often called the Tortoise and Hare approach. The ability to solve this efficiently demonstrates strong logical reasoning and understanding of time-space trade-offs, as the optimal solution requires O(n) time and O(1) space.

Medium
Goldman Sachs
78

What is the approach to find the longest substring without repeating characters?

Interviewers use this to assess sliding window pattern recognition and character tracking skills. They want to see if you can dynamically adjust the window size based on duplicate detection. It demonstrates efficient string processing and state management.

Medium
79

How would you calculate the sum of prime numbers up to N?

This question evaluates a candidate's familiarity with mathematical algorithms and optimization techniques. It distinguishes between brute-force primality testing and more efficient methods like the Sieve of Eratosthenes. Interviewers assess the ability to balance code simplicity with performance requirements for larger inputs.

Medium
Infosys
80

How do you rotate a matrix by 90 degrees clockwise?

Matrix rotation is a common interview problem that checks spatial reasoning and algorithmic precision. It evaluates if candidates can derive the transformation formula and implement it efficiently without extra space.

Medium
Amazon
81

How do you find the Lowest Common Ancestor in a general Binary Tree?

This tests your ability to adapt algorithms when constraints (like BST ordering) are removed.

Medium
Amazon
82

How can you compute the product of all array elements except self?

Interviewers use this to assess a candidate's ability to think outside the box regarding division operations, especially when zero is involved. They want to see if you can construct prefix and suffix products to solve the problem without using division. This demonstrates advanced array manipulation skills and attention to edge cases.

Medium
83

What are some real-world applications of a doubly-linked list?

This question moves beyond theory to assess practical application of data structures. Interviewers want to see if the candidate understands when and why to choose a doubly-linked list over other structures like arrays or singly-linked lists. It demonstrates depth of knowledge regarding performance characteristics and memory usage.

Medium
Infosys
84

How do you find the maximum sum subarray with no consecutive elements?

This problem evaluates the ability to define state transitions in dynamic programming where choices affect future possibilities. It distinguishes candidates who understand DP from those who only know Kadane's algorithm.

Medium
Amazon
85

How do you calculate the lowest common ancestor in a binary search tree?

It tests your ability to leverage specific tree properties (BST ordering) to solve problems faster than general tree approaches. Interviewers want to see if you can write concise, optimal code that exploits the sorted nature of BSTs. It also checks your understanding of recursion and path finding.

Medium
Amazon
86

How do you determine ongoing events for specific query times?

Interviewers ask this to evaluate your understanding of interval algorithms and data structure optimization. They want to see if you can move beyond naive O(n^2) solutions to more efficient approaches like sorting, binary search, or sweep-line algorithms. It demonstrates your capacity to solve real-world problems involving temporal data with performance constraints in mind.

Medium
Google
87

What is the Longest Increasing Subsequence problem and how do you solve it?

Interviewers use this to test LIS algorithm knowledge. They want to see if you can derive the O(n^2) DP solution or the O(n log n) patience sorting approach. It demonstrates sequence analysis skills.

Medium
88

How do you delete a node without access to its parent in a linked list?

This classic problem assesses fundamental data structure knowledge and logical thinking under constraints. Interviewers look for the ability to realize that copying the next node's data and bypassing it is the standard solution when the previous node is inaccessible. It also checks if candidates consider the edge case of deleting the tail node.

Medium
Microsoft
89

How do you calculate the maximum possible sum of products?

Interviewers ask this to test the candidate's ability to apply a greedy approach to optimization problems. They want to see if the candidate understands that pairing largest with largest maximizes the sum of products. It checks sorting and pairing logic.

Medium
Infosys
90

What is the strategy to find the Top K Frequent Elements in an array?

Interviewers use this to test frequency counting and selection algorithms. They want to see if you can combine hash maps with heaps or buckets to solve the problem efficiently. It demonstrates multi-step problem decomposition.

Medium
91

What are the common views in Binary Tree traversal questions?

Tests breadth of knowledge regarding tree traversals and level-order processing.

Medium
Amazon
92

How do you find the intersection point of two linked lists?

Intersection problems appear in graph theory and memory layout debugging. It checks if you can solve problems without extra space (O(1) space solution). Efficiency is critical in high-frequency trading environments.

Medium
Goldman Sachs
93

What is Heap Sort and how is it implemented?

Heap Sort demonstrates understanding of tree structures and in-place sorting algorithms with guaranteed O(n log n) complexity.

Medium
Microsoft Corporation
94

How do you find all triplets with zero sum in an array?

Interviewers ask this to evaluate a candidate's ability to optimize brute-force solutions from O(n^3) to O(n^2). They want to see if the candidate can recognize when to use sorting and the two-pointer approach to reduce complexity. Additionally, it assesses attention to detail regarding edge cases like duplicate triplets and ensuring the solution is robust against various input scenarios.

Medium
Google
95

How do you implement Topological Sorting for a Directed Acyclic Graph?

Interviewers ask this to test graph ordering skills. They want to see if you can handle dependencies and detect cycles implicitly. It demonstrates practical scheduling logic.

Medium
96

How do you implement the merge sort algorithm for sorting arrays?

Merge sort is a standard benchmark for understanding recursive algorithms and stable sorting. Interviewers evaluate your ability to break down problems into sub-problems and merge results efficiently. It tests knowledge of time complexity consistency regardless of input order. This is often contrasted with quicksort to gauge depth of algorithmic knowledge.

Medium
97

How do you find the container with the most water in an array?

This question evaluates a candidate's ability to apply the two-pointer technique to geometric problems. Interviewers look for the insight that moving the shorter line inward is the only viable strategy to potentially increase area. It tests logical deduction and mathematical reasoning regarding area constraints.

Medium
98

How do you solve the Word Break problem efficiently?

Interviewers ask this to test string segmentation and DP state transitions. They want to see if you can break the string into valid substrings. It demonstrates recursive thinking with memoization.

Medium
99

What is the maximum subarray sum problem and how do you solve it?

This is a standard question to evaluate dynamic programming intuition and the ability to recognize overlapping subproblems. Interviewers want to see if you can derive Kadane's algorithm from first principles rather than just memorizing it. It tests logical reasoning about when to reset a subarray sum versus extending it.

Medium
100

How would you solve the maximum subarray sum problem using Kadane's Algorithm?

Kadane's Algorithm is a staple in technical interviews because it bridges the gap between brute force and dynamic programming. Interviewers want to see if candidates can recognize overlapping subproblems and make optimal local choices. It demonstrates the ability to transform an O(n^2) problem into an O(n) solution efficiently.

Medium
Infosys
101

Explain the concept of graph components and their types?

Interviewers ask this to gauge your foundational knowledge of data structures and algorithms. They want to see if you can distinguish between different types of connectivity in graphs, which is crucial for solving problems related to networks, social graphs, and dependency resolution. It also assesses your ability to articulate complex theoretical concepts clearly.

Medium
Microsoft Corporation
102

How do you delete a node given only its pointer in a singly linked list?

This question evaluates your fundamental grasp of linked list mechanics and edge case handling. Interviewers look for your ability to realize that you cannot access the previous node to update its next pointer. It tests creativity in solving problems within strict constraints and your understanding of time complexity trade-offs.

Medium
Microsoft
103

How do you find a subarray with a specific sum in non-negative numbers?

Interviewers ask this to verify knowledge of the sliding window technique, which is crucial for array problems. They want to ensure the candidate understands why this method works specifically for non-negative numbers due to monotonicity. It also tests the ability to reduce time complexity from O(n^2) to O(n).

Medium
Google
104

What is the Coin Change problem and how do you solve it?

Interviewers use this to test DP table construction and state transitions. They want to see if you can break down the problem into smaller subproblems. It demonstrates optimization and recurrence relation skills.

Medium
105

How do you find the next greater element for each element in an array?

Finding the next greater element is a fundamental pattern used in various real-world scenarios like stock analysis and resource allocation. It tests the ability to apply stack-based solutions for range queries.

Medium
Amazon
106

What is the optimal approach to find a subarray with a given sum?

This classic problem evaluates knowledge of the sliding window technique and prefix sum concepts. Interviewers want to see if you can solve it in linear time O(n). It also tests handling of negative numbers and non-negative constraints.

Medium
Google
107

What is the Maximum Product Cutting problem and how do you solve it?

Interviewers use this to test optimization and mathematical insight. They want to see if you can derive the optimal cut sizes (mostly 3s). It demonstrates pattern recognition.

Medium
108

What is the Course Schedule problem and how do you solve it?

Interviewers use this to test graph theory applications, specifically topological sorting. They want to see if you can model dependencies as a directed graph and detect cycles. It demonstrates real-world problem modeling skills.

Medium
109

How can you reverse a linked list iteratively and recursively?

Reversing a linked list is fundamental to testing a candidate's grasp of pointer manipulation and recursion depth limits. Interviewers want to see if you understand how memory references work in a linked structure. Iterative solutions demonstrate control flow mastery, while recursive solutions test understanding of the call stack and base cases. It is often a precursor to more complex problems involving graph traversal or tree rotations.

Medium
110

What is the minimum number of meeting rooms needed for overlapping meetings?

Meeting room scheduling is a real-world application of interval management. Interviewers ask this to see if you can optimize resources using efficient data structures. It evaluates your skill in transforming a temporal problem into a computational one using heaps.

Medium
Microsoft Corporation
111

What is the algorithm to find the Lowest Common Ancestor in a BST?

Interviewers use this to test specific knowledge of BST properties. They want to see if you can exploit the sorted nature of the tree to find the LCA in O(h) time without traversing the whole tree. It demonstrates efficient search strategies.

Medium
112

How do you clone a graph given a reference to a node?

Interviewers ask this to test graph traversal skills and the ability to handle cycles in graphs. They want to see if you can use a hash map to track visited nodes and prevent infinite loops. It demonstrates careful state management in graph problems.

Medium
113

What is the approach to detect a cycle in a directed graph?

Cycle detection is critical for dependency resolution, deadlock prevention, and topological sorting scenarios. Interviewers assess your ability to manage visited states and distinguish between active and completed nodes. It tests logical reasoning about graph properties and the correctness of traversal algorithms. Understanding this concept is essential for systems that rely on DAG structures.

Medium
114

How can you count strings formed under specific character constraints?

Interviewers use this to gauge a candidate's proficiency in dynamic programming, specifically regarding state transitions and counting problems. It requires breaking down a complex combinatorial problem into smaller subproblems. The ability to define states based on remaining counts of characters and transition between them efficiently is key to solving this.

Medium
Google
115

How do you calculate the lowest common ancestor in a binary tree?

Tree problems are common in Amazon interviews to test logical reasoning and recursion skills. The LCA problem specifically checks if you can traverse a tree to find relationships between nodes. It demonstrates your ability to break down a complex problem into smaller sub-problems.

Medium
Amazon
116

What is the best approach to solve the Two Sum problem?

The Two Sum problem is a standard benchmark for evaluating a candidate's ability to trade off time and space complexity. Interviewers look for the transition from brute force solutions to optimized approaches using hash maps. It demonstrates logical reasoning and familiarity with common data structure patterns used in real-world applications.

Medium
Infosys
117

How do you find a subarray with a given sum in non-negative numbers?

Interviewers ask this to test knowledge of the sliding window technique, which is highly relevant for array and stream processing problems. Since the numbers are non-negative, the sum increases monotonically, allowing for an efficient single-pass solution. It demonstrates a candidate's ability to optimize space and time complexity by avoiding unnecessary iterations.

Medium
Google
118

How do you find the lowest common ancestor in a binary search tree?

Finding the LCA in a BST is more efficient than in a general binary tree due to ordering properties. Interviewers want to see if candidates recognize these properties to achieve O(H) time complexity instead of O(N).

Medium
Amazon
119

How do you detect a loop in a linked list and find its start?

Interviewers ask this to evaluate a candidate's fundamental understanding of data structures, particularly how pointers work in memory. They want to see if the candidate can apply efficient algorithms like Floyd's Tortoise and Hare rather than using hash sets which consume extra space. This problem also assesses logical reasoning skills and the ability to handle edge cases where loops might be complex or non-existent.

Medium
Goldman Sachs
120

How do you compute the product of all array elements except self?

This problem evaluates your ability to solve constraints creatively, specifically avoiding division which might cause overflow or fail with zeros. Interviewers want to see if you can construct prefix and suffix products efficiently in linear time. It tests your skill in manipulating arrays to store intermediate results without excessive auxiliary space.

Medium
121

How do you detect overlapping rectangles in a set?

Interviewers ask this to test spatial reasoning and the ability to formulate conditions for intersection. It checks if candidates can break down the problem into coordinate comparisons. It also evaluates optimization strategies for large sets.

Medium
Infosys
122

How do you count the number of islands in a grid?

Interviewers ask this to test 2D array traversal and component counting skills. They want to see if you can use DFS or BFS to mark visited land cells. It demonstrates graph traversal on grids.

Medium
123

What is the minimum number of meeting rooms required for overlapping meetings?

This problem evaluates your skill in sorting intervals and using efficient data structures like heaps to track active resources. It simulates real-world scenarios where managing limited resources (rooms, servers) is critical. The interviewer looks for an optimal solution better than brute force.

Medium
Microsoft Corporation
124

Explain the concept of graph components and their types?

Interviewers ask this to verify your foundational knowledge of data structures beyond basic arrays and lists. They want to see if you can distinguish between different types of connectivity in graphs, which is crucial for network analysis, social graph problems, and dependency resolution systems. It tests your ability to define mathematical concepts clearly and relate them to practical algorithmic applications like DFS or BFS traversals.

Medium
Microsoft
125

How do you reverse a linked list iteratively versus recursively?

Linked list reversal is a staple interview question because it directly tests core data structure manipulation skills. Interviewers want to see if you understand pointer references and how to break and rebuild links. The recursive version specifically checks your comfort with the call stack and base cases. It also reveals your ability to write clean, readable code for complex pointer operations.

Medium
126

What is the Spiral Matrix traversal algorithm and how does it work?

This question assesses a candidate's ability to manage multiple variables and boundaries simultaneously. Interviewers look for clean code that handles row and column limits dynamically. It tests simulation skills and the ability to avoid infinite loops or out-of-bounds access.

Medium
127

What is the best strategy to buy and sell stock once?

This question assesses your ability to maintain state while iterating through data to find optimal solutions. Interviewers look for candidates who can recognize that tracking the minimum price seen so far is sufficient to calculate maximum profit. It demonstrates logical thinking and the capacity to simplify complex financial problems into linear scans.

Medium

Ready to practice dsa questions?

Get AI-powered feedback on your answers with our mock interview simulator.

Start Free Practice