Interview Q&A · questions with model answers

Data Structures Interview Questions

Part of the study plan for: Machine Learning Engineer

Ordered by how often they're asked. Most-asked answers are free to read in full; members see every answer and can rate their confidence on each.

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

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

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

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

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

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

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

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

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

    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'.

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

    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'.

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

    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'.

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

    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'.

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

    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'.

  10. How would you approach the classic problem 'invert binary tree'?

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

  11. How would you approach the classic problem 'course schedule'?

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

  12. How would you approach the classic problem 'coin change'?

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

  13. How would you approach the classic problem 'product except self'?

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

  14. How would you approach the classic problem 'clone graph'?

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

  15. How would you approach the classic problem 'trapping rain water'?

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

  16. How would you approach the classic problem 'serialize/deserialize tree'?

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

  17. How would you approach the classic problem 'implement trie'?

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

  18. How would you approach the classic problem 'search rotated array'?

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

  19. How would you approach the classic problem 'meeting rooms'?

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

  20. How would you approach the classic problem 'palindrome linked list'?

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

  21. How would you approach the classic problem 'spiral matrix'?

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

  22. How would you approach the classic problem 'house robber'?

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

  23. How would you approach the classic problem 'unique paths'?

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

  24. How would you approach the classic problem 'minimum window substring'?

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

  25. How would you approach the classic problem 'daily temperatures'?

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

  26. How would you approach the classic problem 'asteroid collision'?

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

  27. How would you approach the classic problem 'flatten nested list'?

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

  28. How would you approach the classic problem 'lowest common ancestor'?

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

  29. How would you approach the classic problem 'word break'?

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

  30. How would you approach the classic problem 'merge k sorted lists'?

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

  31. How would you approach the classic problem 'median of two sorted arrays'?

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

  32. How would you approach the classic problem 'design hit counter'?

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

  33. How would you approach the classic problem 'find peak element'?

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

  34. How would you approach the classic problem 'alien dictionary'?

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

  35. How would you approach the classic problem 'add two numbers'?

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

  36. How would you approach the classic problem 'rotate image'?

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

  37. How would you approach the classic problem 'jump game'?

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

  38. How would you approach the classic problem 'edit distance'?

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

  39. How would you approach the classic problem 'sliding window maximum'?

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

  40. How would you approach the classic problem 'next greater element'?

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

  41. How would you approach the classic problem 'decode string'?

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

Was this page helpful?

Report a mistake