Interview Q&A · 99 questions · 22 answered publicly

Data Structures Interview Questions

Ordered by how often they're asked. Sign in free to see every answer, rate your confidence and run timed mock interviews.

  1. Most asked Explain a list and its typical time complexities.

    Summary

    Ordered mutable sequence; amortised O(1) append; O(n) insert/delete in middle.

    Longer Answer

    Ordered mutable sequence; amortised O(1) append; O(n) insert/delete in middle. DSA structure: list.

    Key Points

    • Ordered mutable sequence; amortised O(1) append; O(n) insert/delete in middle
    • DSA structure: list
    • Relevant areas: Dsa, List
    • Use the answer to connect the concept back to a realistic production or interview scenario for 'Explain a list and its typical time complexities.'

    Comparison / Tradeoffs

    Aspect Notes
    Core idea Ordered mutable sequence; amortised O(1) append; O(n) insert/delete in middle.
    Practical tradeoff DSA structure: list.

    Permalink

  2. Most asked Explain a dict and its typical time complexities.

    Summary

    Hash map of keys to values; average O(1) get/set; keys must be hashable.

    Longer Answer

    Hash map of keys to values; average O(1) get/set; keys must be hashable. DSA structure: dict.

    Key Points

    • Hash map of keys to values; average O(1) get/set; keys must be hashable
    • DSA structure: dict
    • Relevant areas: Dsa, Dict
    • Use the answer to connect the concept back to a realistic production or interview scenario for 'Explain a dict and its typical time complexities.'

    Comparison / Tradeoffs

    Aspect Notes
    Core idea Hash map of keys to values; average O(1) get/set; keys must be hashable.
    Practical tradeoff DSA structure: dict.

    Permalink

  3. Most asked Explain a set and its typical time complexities.

    Summary

    Unordered unique hashable elements; O(1) average membership.

    Longer Answer

    Unordered unique hashable elements; O(1) average membership. DSA structure: set.

    Key Points

    • Unordered unique hashable elements; O(1) average membership
    • DSA structure: set
    • Relevant areas: Dsa, Set
    • Use the answer to connect the concept back to a realistic production or interview scenario for 'Explain a set and its typical time complexities.'

    Comparison / Tradeoffs

    Aspect Notes
    Core idea Unordered unique hashable elements; O(1) average membership.
    Practical tradeoff DSA structure: set.

    Permalink

  4. Most asked Explain a hash table and its typical time complexities.

    Summary

    Array + hash function + collision strategy (chaining/open addressing).

    Longer Answer

    Array + hash function + collision strategy (chaining/open addressing). DSA structure: hash table.

    Key Points

    • Array + hash function + collision strategy (chaining/open addressing)
    • DSA structure: hash table
    • Relevant areas: Dsa, Hash
    • Use the answer to connect the concept back to a realistic production or interview scenario for 'Explain a hash table and its typical time complexities.'

    Comparison / Tradeoffs

    Aspect Notes
    Core idea Array + hash function + collision strategy (chaining/open addressing).
    Practical tradeoff DSA structure: hash table.

    Permalink

  5. Most asked Describe BFS and when you would use it.

    Summary

    Level-order graph/tree traversal using a queue; shortest path in unweighted graphs.

    Longer Answer

    Level-order graph/tree traversal using a queue; shortest path in unweighted graphs. Core algorithm topic: BFS.

    Key Points

    • Level-order graph/tree traversal using a queue; shortest path in unweighted graphs
    • Core algorithm topic: BFS
    • Relevant areas: Dsa, Algorithms
    • Use the answer to connect the concept back to a realistic production or interview scenario for 'Describe BFS and when you would use it.'

    Comparison / Tradeoffs

    Aspect Notes
    Core idea Level-order graph/tree traversal using a queue; shortest path in unweighted graphs.
    Practical tradeoff Core algorithm topic: BFS.

    Permalink

  6. Most asked Describe DFS and when you would use it.

    Summary

    Deep exploration with stack/recursion; cycle detection, topological sort building block.

    Longer Answer

    Deep exploration with stack/recursion; cycle detection, topological sort building block. Core algorithm topic: DFS.

    Key Points

    • Deep exploration with stack/recursion; cycle detection, topological sort building block
    • Core algorithm topic: DFS
    • Relevant areas: Dsa, Algorithms
    • Use the answer to connect the concept back to a realistic production or interview scenario for 'Describe DFS and when you would use it.'

    Comparison / Tradeoffs

    Aspect Notes
    Core idea Deep exploration with stack/recursion; cycle detection, topological sort building block.
    Practical tradeoff Core algorithm topic: DFS.

    Permalink

  7. Most asked Describe binary search and when you would use it.

    Summary

    O(log n) search on sorted arrays; careful mid/overflow and boundaries.

    Longer Answer

    O(log n) search on sorted arrays; careful mid/overflow and boundaries. Core algorithm topic: binary search.

    Key Points

    • O(log n) search on sorted arrays; careful mid/overflow and boundaries
    • Core algorithm topic: binary search
    • Relevant areas: Dsa, Algorithms
    • Use the answer to connect the concept back to a realistic production or interview scenario for 'Describe binary search and when you would use it.'

    Comparison / Tradeoffs

    Aspect Notes
    Core idea O(log n) search on sorted arrays; careful mid/overflow and boundaries.
    Practical tradeoff Core algorithm topic: binary search.

    Permalink

  8. Most asked Describe two pointers and when you would use it.

    Summary

    Coordinate indices from ends or same direction to solve array problems in O(n).

    Longer Answer

    Coordinate indices from ends or same direction to solve array problems in O(n). Core algorithm topic: two pointers.

    Key Points

    • Coordinate indices from ends or same direction to solve array problems in O(n)
    • Core algorithm topic: two pointers
    • Relevant areas: Dsa, Algorithms
    • Use the answer to connect the concept back to a realistic production or interview scenario for 'Describe two pointers and when you would use it.'

    Comparison / Tradeoffs

    Aspect Notes
    Core idea Coordinate indices from ends or same direction to solve array problems in O(n).
    Practical tradeoff Core algorithm topic: two pointers.

    Permalink

  9. Most asked Describe sliding window and when you would use it.

    Summary

    Maintain a window invariant for subarray/substring problems.

    Longer Answer

    Maintain a window invariant for subarray/substring problems. Core algorithm topic: sliding window.

    Key Points

    • Maintain a window invariant for subarray/substring problems
    • Core algorithm topic: sliding window
    • Relevant areas: Dsa, Algorithms
    • Use the answer to connect the concept back to a realistic production or interview scenario for 'Describe sliding window and when you would use it.'

    Comparison / Tradeoffs

    Aspect Notes
    Core idea Maintain a window invariant for subarray/substring problems.
    Practical tradeoff Core algorithm topic: sliding window.

    Permalink

  10. Most asked Describe dynamic programming and when you would use it.

    Summary

    Optimal substructure + overlapping subproblems; memoize or tabulate.

    Longer Answer

    Optimal substructure + overlapping subproblems; memoize or tabulate. Core algorithm topic: dynamic programming.

    Key Points

    • Optimal substructure + overlapping subproblems; memoize or tabulate
    • Core algorithm topic: dynamic programming
    • Relevant areas: Dsa, Algorithms
    • Use the answer to connect the concept back to a realistic production or interview scenario for 'Describe dynamic programming and when you would use it.'

    Comparison / Tradeoffs

    Aspect Notes
    Core idea Optimal substructure + overlapping subproblems; memoize or tabulate.
    Practical tradeoff Core algorithm topic: dynamic programming.

    Permalink

  11. Most asked Describe LRU cache design and when you would use it.

    Summary

    Hash map + doubly linked list for O(1) get/put.

    Longer Answer

    Hash map + doubly linked list for O(1) get/put. Core algorithm topic: LRU cache design.

    Key Points

    • Hash map + doubly linked list for O(1) get/put
    • Core algorithm topic: LRU cache design
    • Relevant areas: Dsa, Algorithms
    • Use the answer to connect the concept back to a realistic production or interview scenario for 'Describe LRU cache design and when you would use it.'

    Comparison / Tradeoffs

    Aspect Notes
    Core idea Hash map + doubly linked list for O(1) get/put.
    Practical tradeoff Core algorithm topic: LRU cache design.

    Permalink

  12. Most asked Explain a deque and its typical time complexities.

    Summary

    Double-ended queue with O(1) append/pop from both ends.

    Longer Answer

    Double-ended queue with O(1) append/pop from both ends. DSA structure: deque.

    Key Points

    • Double-ended queue with O(1) append/pop from both ends
    • DSA structure: deque
    • Relevant areas: Dsa, Deque
    • Use the answer to connect the concept back to a realistic production or interview scenario for 'Explain a deque and its typical time complexities.'

    Comparison / Tradeoffs

    Aspect Notes
    Core idea Double-ended queue with O(1) append/pop from both ends.
    Practical tradeoff DSA structure: deque.

    Permalink

  13. Most asked Explain a heapq / priority queue and its typical time complexities.

    Summary

    Binary heap for min-priority operations in O(log n).

    Longer Answer

    Binary heap for min-priority operations in O(log n). DSA structure: heapq / priority queue.

    Key Points

    • Binary heap for min-priority operations in O(log n)
    • DSA structure: heapq / priority queue
    • Relevant areas: Dsa, Heapq
    • Use the answer to connect the concept back to a realistic production or interview scenario for 'Explain a heapq / priority queue and its typical time complexities.'

    Comparison / Tradeoffs

    Aspect Notes
    Core idea Binary heap for min-priority operations in O(log n).
    Practical tradeoff DSA structure: heapq / priority queue.

    Permalink

  14. Most asked How would you approach the classic problem 'two-sum'?

    Summary

    Clarify constraints, identify the right pattern (two pointers, BFS/DFS, heap, DP, etc.), state time/space complexity, and discuss edge cases for 'two-sum'.

    Longer Answer

    Clarify constraints, identify the right pattern (two pointers, BFS/DFS, heap, DP, etc.), state time/space complexity, and discuss edge cases for 'two-sum'. Pattern recognition for two-sum.

    Key Points

    • Clarify constraints, identify the right pattern (two pointers, BFS/DFS, heap, DP, etc.), state time/space complexity, and discuss edge cases for 'two-sum'
    • Pattern recognition for two-sum
    • Relevant areas: Dsa, Problem Solving
    • Use the answer to connect the concept back to a realistic production or interview scenario for 'How would you approach the classic problem 'two-sum'?'

    Comparison / Tradeoffs

    Aspect Notes
    Core idea Clarify constraints, identify the right pattern (two pointers, BFS/DFS, heap, DP, etc.), state time/space complexity, and discuss edge cases for 'two-sum'.
    Practical tradeoff Pattern recognition for two-sum.

    Permalink

  15. Most asked How would you approach the classic problem 'merge intervals'?

    Summary

    Clarify constraints, identify the right pattern (two pointers, BFS/DFS, heap, DP, etc.), state time/space complexity, and discuss edge cases for 'merge intervals'.

    Longer Answer

    Clarify constraints, identify the right pattern (two pointers, BFS/DFS, heap, DP, etc.), state time/space complexity, and discuss edge cases for 'merge intervals'. Pattern recognition for merge intervals.

    Key Points

    • Clarify constraints, identify the right pattern (two pointers, BFS/DFS, heap, DP, etc.), state time/space complexity, and discuss edge cases for 'merge intervals'
    • Pattern recognition for merge intervals
    • Relevant areas: Dsa, Problem Solving
    • Use the answer to connect the concept back to a realistic production or interview scenario for 'How would you approach the classic problem 'merge intervals'?'

    Comparison / Tradeoffs

    Aspect Notes
    Core idea Clarify constraints, identify the right pattern (two pointers, BFS/DFS, heap, DP, etc.), state time/space complexity, and discuss edge cases for 'merge intervals'.
    Practical tradeoff Pattern recognition for merge intervals.

    Permalink

  16. Most asked How would you approach the classic problem 'group anagrams'?

    Summary

    Clarify constraints, identify the right pattern (two pointers, BFS/DFS, heap, DP, etc.), state time/space complexity, and discuss edge cases for 'group anagrams'.

    Longer Answer

    Clarify constraints, identify the right pattern (two pointers, BFS/DFS, heap, DP, etc.), state time/space complexity, and discuss edge cases for 'group anagrams'. Pattern recognition for group anagrams.

    Key Points

    • Clarify constraints, identify the right pattern (two pointers, BFS/DFS, heap, DP, etc.), state time/space complexity, and discuss edge cases for 'group anagrams'
    • Pattern recognition for group anagrams
    • Relevant areas: Dsa, Problem Solving
    • Use the answer to connect the concept back to a realistic production or interview scenario for 'How would you approach the classic problem 'group anagrams'?'

    Comparison / Tradeoffs

    Aspect Notes
    Core idea Clarify constraints, identify the right pattern (two pointers, BFS/DFS, heap, DP, etc.), state time/space complexity, and discuss edge cases for 'group anagrams'.
    Practical tradeoff Pattern recognition for group anagrams.

    Permalink

  17. Most asked How would you approach the classic problem 'valid parentheses'?

    Summary

    Clarify constraints, identify the right pattern (two pointers, BFS/DFS, heap, DP, etc.), state time/space complexity, and discuss edge cases for 'valid parentheses'.

    Longer Answer

    Clarify constraints, identify the right pattern (two pointers, BFS/DFS, heap, DP, etc.), state time/space complexity, and discuss edge cases for 'valid parentheses'. Pattern recognition for valid parentheses.

    Key Points

    • Clarify constraints, identify the right pattern (two pointers, BFS/DFS, heap, DP, etc.), state time/space complexity, and discuss edge cases for 'valid parentheses'
    • Pattern recognition for valid parentheses
    • Relevant areas: Dsa, Problem Solving
    • Use the answer to connect the concept back to a realistic production or interview scenario for 'How would you approach the classic problem 'valid parentheses'?'

    Comparison / Tradeoffs

    Aspect Notes
    Core idea Clarify constraints, identify the right pattern (two pointers, BFS/DFS, heap, DP, etc.), state time/space complexity, and discuss edge cases for 'valid parentheses'.
    Practical tradeoff Pattern recognition for valid parentheses.

    Permalink

  18. Most asked How would you approach the classic problem 'binary tree level order'?

    Summary

    Clarify constraints, identify the right pattern (two pointers, BFS/DFS, heap, DP, etc.), state time/space complexity, and discuss edge cases for 'binary tree level order'.

    Longer Answer

    Clarify constraints, identify the right pattern (two pointers, BFS/DFS, heap, DP, etc.), state time/space complexity, and discuss edge cases for 'binary tree level order'. Pattern recognition for binary tree level order.

    Key Points

    • Clarify constraints, identify the right pattern (two pointers, BFS/DFS, heap, DP, etc.), state time/space complexity, and discuss edge cases for 'binary tree level order'
    • Pattern recognition for binary tree level order
    • Relevant areas: Dsa, Problem Solving
    • Use the answer to connect the concept back to a realistic production or interview scenario for 'How would you approach the classic problem 'binary tree level order'?'

    Comparison / Tradeoffs

    Aspect Notes
    Core idea Clarify constraints, identify the right pattern (two pointers, BFS/DFS, heap, DP, etc.), state time/space complexity, and discuss edge cases for 'binary tree level order'.
    Practical tradeoff Pattern recognition for binary tree level order.

    Permalink

  19. Most asked How would you approach the classic problem 'longest substring without repeating'?

    Summary

    Clarify constraints, identify the right pattern (two pointers, BFS/DFS, heap, DP, etc.), state time/space complexity, and discuss edge cases for 'longest substring without repeating'.

    Longer Answer

    Clarify constraints, identify the right pattern (two pointers, BFS/DFS, heap, DP, etc.), state time/space complexity, and discuss edge cases for 'longest substring without repeating'. Pattern recognition for longest substring without repeating.

    Key Points

    • Clarify constraints, identify the right pattern (two pointers, BFS/DFS, heap, DP, etc.), state time/space complexity, and discuss edge cases for 'longest substring without repeating'
    • Pattern recognition for longest substring without repeating
    • Relevant areas: Dsa, Problem Solving
    • Use the answer to connect the concept back to a realistic production or interview scenario for 'How would you approach the classic problem 'longest substring without repeating'?'

    Comparison / Tradeoffs

    Aspect Notes
    Core idea Clarify constraints, identify the right pattern (two pointers, BFS/DFS, heap, DP, etc.), state time/space complexity, and discuss edge cases for 'longest substring without repeating'.
    Practical tradeoff Pattern recognition for longest substring without repeating.

    Permalink

  20. Most asked How would you approach the classic problem 'number of islands'?

    Summary

    Clarify constraints, identify the right pattern (two pointers, BFS/DFS, heap, DP, etc.), state time/space complexity, and discuss edge cases for 'number of islands'.

    Longer Answer

    Clarify constraints, identify the right pattern (two pointers, BFS/DFS, heap, DP, etc.), state time/space complexity, and discuss edge cases for 'number of islands'. Pattern recognition for number of islands.

    Key Points

    • Clarify constraints, identify the right pattern (two pointers, BFS/DFS, heap, DP, etc.), state time/space complexity, and discuss edge cases for 'number of islands'
    • Pattern recognition for number of islands
    • Relevant areas: Dsa, Problem Solving
    • Use the answer to connect the concept back to a realistic production or interview scenario for 'How would you approach the classic problem 'number of islands'?'

    Comparison / Tradeoffs

    Aspect Notes
    Core idea Clarify constraints, identify the right pattern (two pointers, BFS/DFS, heap, DP, etc.), state time/space complexity, and discuss edge cases for 'number of islands'.
    Practical tradeoff Pattern recognition for number of islands.

    Permalink

  21. Most asked How would you approach the classic problem 'kth largest element'?

    Summary

    Clarify constraints, identify the right pattern (two pointers, BFS/DFS, heap, DP, etc.), state time/space complexity, and discuss edge cases for 'kth largest element'.

    Longer Answer

    Clarify constraints, identify the right pattern (two pointers, BFS/DFS, heap, DP, etc.), state time/space complexity, and discuss edge cases for 'kth largest element'. Pattern recognition for kth largest element.

    Key Points

    • Clarify constraints, identify the right pattern (two pointers, BFS/DFS, heap, DP, etc.), state time/space complexity, and discuss edge cases for 'kth largest element'
    • Pattern recognition for kth largest element
    • Relevant areas: Dsa, Problem Solving
    • Use the answer to connect the concept back to a realistic production or interview scenario for 'How would you approach the classic problem 'kth largest element'?'

    Comparison / Tradeoffs

    Aspect Notes
    Core idea Clarify constraints, identify the right pattern (two pointers, BFS/DFS, heap, DP, etc.), state time/space complexity, and discuss edge cases for 'kth largest element'.
    Practical tradeoff Pattern recognition for kth largest element.

    Permalink

  22. Most asked How would you approach the classic problem 'top k frequent'?

    Summary

    Clarify constraints, identify the right pattern (two pointers, BFS/DFS, heap, DP, etc.), state time/space complexity, and discuss edge cases for 'top k frequent'.

    Longer Answer

    Clarify constraints, identify the right pattern (two pointers, BFS/DFS, heap, DP, etc.), state time/space complexity, and discuss edge cases for 'top k frequent'. Pattern recognition for top k frequent.

    Key Points

    • Clarify constraints, identify the right pattern (two pointers, BFS/DFS, heap, DP, etc.), state time/space complexity, and discuss edge cases for 'top k frequent'
    • Pattern recognition for top k frequent
    • Relevant areas: Dsa, Problem Solving
    • Use the answer to connect the concept back to a realistic production or interview scenario for 'How would you approach the classic problem 'top k frequent'?'

    Comparison / Tradeoffs

    Aspect Notes
    Core idea Clarify constraints, identify the right pattern (two pointers, BFS/DFS, heap, DP, etc.), state time/space complexity, and discuss edge cases for 'top k frequent'.
    Practical tradeoff Pattern recognition for top k frequent.

    Permalink

  23. Explain a tuple and its typical time complexities.
  24. Explain a BST and its typical time complexities.
  25. Explain a graph (adjacency list) and its typical time complexities.
  26. What is Big-O?
  27. Why is dict get O(1) average?
  28. In Python DSA interviews, explain: list vs deque for queue.
  29. Explain a stack and its typical time complexities.
  30. Explain a queue and its typical time complexities.
  31. Explain a linked list and its typical time complexities.
  32. Explain a binary tree and its typical time complexities.
  33. Explain a trie and its typical time complexities.
  34. Explain a union-find (DSU) and its typical time complexities.
  35. Describe prefix sums and when you would use it.
  36. Describe sorting: quicksort and when you would use it.
  37. Describe sorting: mergesort and when you would use it.
  38. Describe Dijkstra and when you would use it.
  39. Describe topological sort and when you would use it.
  40. Describe greedy algorithms and when you would use it.
  41. Describe backtracking and when you would use it.
  42. Describe Kadane's algorithm and when you would use it.
  43. Describe detect cycle in linked list and when you would use it.
  44. Big-Ω vs Big-Θ?
  45. Amortized analysis?
  46. Time vs space tradeoff?
  47. Best/average/worst case?
  48. In Python DSA interviews, explain: __hash__ and __eq__.
  49. In Python DSA interviews, explain: generators and memory.
  50. How would you approach the classic problem 'invert binary tree'?
  51. How would you approach the classic problem 'course schedule'?
  52. How would you approach the classic problem 'coin change'?
  53. How would you approach the classic problem 'product except self'?
  54. How would you approach the classic problem 'clone graph'?
  55. How would you approach the classic problem 'trapping rain water'?
  56. How would you approach the classic problem 'serialize/deserialize tree'?
  57. How would you approach the classic problem 'implement trie'?
  58. How would you approach the classic problem 'search rotated array'?
  59. How would you approach the classic problem 'meeting rooms'?
  60. How would you approach the classic problem 'palindrome linked list'?
  61. How would you approach the classic problem 'spiral matrix'?
  62. How would you approach the classic problem 'house robber'?
  63. How would you approach the classic problem 'unique paths'?
  64. How would you approach the classic problem 'minimum window substring'?
  65. How would you approach the classic problem 'daily temperatures'?
  66. How would you approach the classic problem 'asteroid collision'?
  67. How would you approach the classic problem 'flatten nested list'?
  68. Explain a frozenset and its typical time complexities.
  69. Explain a AVL / red-black tree and its typical time complexities.
  70. Explain a graph (adjacency matrix) and its typical time complexities.
  71. Explain a bloom filter and its typical time complexities.
  72. Explain a segment tree and its typical time complexities.
  73. Describe sorting: heapsort and when you would use it.
  74. Describe Bellman-Ford and when you would use it.
  75. Describe KMP / string matching and when you would use it.
  76. Describe serialize binary tree and when you would use it.
  77. Stable vs unstable sort?
  78. In-place algorithm?
  79. In Python DSA interviews, explain: dict insertion order.
  80. In Python DSA interviews, explain: list comprehension cost.
  81. In Python DSA interviews, explain: bisect module.
  82. In Python DSA interviews, explain: array vs list.
  83. In Python DSA interviews, explain: setdefault / Counter.
  84. How would you approach the classic problem 'lowest common ancestor'?
  85. How would you approach the classic problem 'word break'?
  86. How would you approach the classic problem 'merge k sorted lists'?
  87. How would you approach the classic problem 'median of two sorted arrays'?
  88. How would you approach the classic problem 'design hit counter'?
  89. How would you approach the classic problem 'find peak element'?
  90. How would you approach the classic problem 'alien dictionary'?
  91. How would you approach the classic problem 'add two numbers'?
  92. How would you approach the classic problem 'rotate image'?
  93. How would you approach the classic problem 'jump game'?
  94. How would you approach the classic problem 'edit distance'?
  95. How would you approach the classic problem 'sliding window maximum'?
  96. How would you approach the classic problem 'next greater element'?
  97. How would you approach the classic problem 'decode string'?
  98. What is the difference between a list and a tuple in Python?
  99. Explain the time complexity of common dictionary operations in Python.