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.
-
Most asked How do you merge overlapping intervals?
Sort by start; scan and merge when current.start <= last.end, else append a new interval.
-
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).
-
Most asked How do you validate a binary search tree?
DFS with allowable (low, high) bounds per node, or check inorder is strictly increasing.
-
How do you report complexity of BFS/DFS?
O(V+E) time with adjacency lists; space O(V) for visited + queue/stack.
-
How should you start a coding interview problem?
Clarify inputs/constraints/examples, state brute force, propose optimized approach with complexity, then code.
-
How do you find connected components in an undirected graph?
DFS/BFS floods from unvisited nodes, or Union-Find on all edges.