Q1. How do you communicate algorithmic tradeoffs during an interview when multiple solutions are possible?
I start with constraints, propose a baseline solution, then compare alternatives by time complexity, memory usage, and implementation risk. Interviewers usually value clear reasoning and pragmatic decision making more than jumping to the fanciest algorithm.
Q2. When would you choose a heap over sorting for top-k problems?
If k is much smaller than n or data is streaming, a heap usually gives better incremental performance and memory behavior. Full sorting is simpler and sometimes acceptable when n is small or when ordered output for all elements is already needed.
Q3. How do you verify correctness for a complex graph algorithm in an interview setting?
I define invariants early, test edge cases manually, and walk through a small example that exercises cycles or disconnected components. This demonstrates both correctness thinking and the ability to catch subtle implementation mistakes.