Top 35 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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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).
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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).
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.
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.
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.
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.
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).
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.
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.
Ready to practice dsa questions?
Get AI-powered feedback on your answers with our mock interview simulator.
Start Free Practice