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 What does Big-O describe in interviews?

    Asymptotic upper bound on growth of time/space as input size grows—not exact runtime on one machine.

  2. Most asked What is Union-Find used for?

    Dynamic connectivity / components with near O(1) amortized union and find (with optimizations).

  3. Most asked What two properties justify DP?

    Optimal substructure and overlapping subproblems.

  4. What is amortized analysis? Give an example.

    Average cost per op over a sequence; dynamic array append is amortized O(1) despite occasional O(n) resizes.

  5. What is an in-place algorithm?

    Uses only a small constant (or logarithmic) amount of extra memory beyond the input.

  6. What is a monotonic stack?

    Stack kept strictly increasing/decreasing to answer next greater/smaller in amortized O(n).

  7. What does a min-stack need beyond a normal stack?

    Track current minimum—often via an auxiliary stack of mins so getMin is O(1).

  8. What is tree diameter?

    Longest path between any two nodes; often computed via heights or two BFS/DFS passes.

  9. What must be true of dict keys in Python?

    They must be hashable (immutable with stable hash) and consistent with equality.

  10. What edge cases should you always test?

    Empty input, single element, duplicates, negatives, overflow/large n, disconnected graphs, skewed trees.

  11. What is a bipartite graph check?

    Try 2-coloring via BFS/DFS; if an edge joins same color, not bipartite.

Was this page helpful?

Report a mistake