How do you decide whether a problem can be solved greedily, and how would you convince yourself a greedy choice actually yields the optimum?

technical-conceptual · Mid level · software-engineering

What the interviewer is really asking

Tests whether the candidate knows the two structural properties that justify greedy, can name a proof technique rather than just trusting intuition, and understands that an unproven greedy is a common source of subtly wrong solutions.

What to say

What to avoid

Example answers

Strong: For a meeting-room/interval problem I picked activities by earliest finish time and justified it with an exchange argument: any optimal schedule's first activity can be swapped for the earliest-finishing one without reducing the count, so greedy is safe. I verified it against a brute-force solution on random inputs before shipping, and they always matched.

Weak: If I can take the best option at each step, I just do that — greedy is simpler than DP and it usually works.

Want questions matched to your role? Paste a job title, job description, or CV and get a personalized set, or go Pro to unlock the full bank.