Interview Q&A · questions with model answers

Algorithms 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 do you merge overlapping intervals?

    Sort by start; scan and merge when current.start <= last.end, else append a new interval.

  2. Most asked How do you get Top K elements efficiently?

    Maintain a size-K heap (min-heap of K for largest K) in O(n log K), or quickselect average O(n).

  3. Most asked How do you validate a binary search tree?

    DFS with allowable (low, high) bounds per node, or check inorder is strictly increasing.

  4. How do you report complexity of BFS/DFS?

    O(V+E) time with adjacency lists; space O(V) for visited + queue/stack.

  5. How should you start a coding interview problem?

    Clarify inputs/constraints/examples, state brute force, propose optimized approach with complexity, then code.

  6. How do you find connected components in an undirected graph?

    DFS/BFS floods from unvisited nodes, or Union-Find on all edges.

Was this page helpful?

Report a mistake