← Greedy Algorithms Quiz: all 8 questions
Greedy Algorithms Quiz · Question 2 of 8
What is the best way to check whether a greedy idea is wrong?
What is the best way to check whether a greedy idea is wrong?
- A.Run it on the sample input only
- B.Look for a counter-example
- C.Check that it is O(n)
- D.Ask whether it uses sorting
Answer & explanation
Correct answer: Look for a counter-example
One input where greedy fails proves it's incorrect (e.g. coin change with [1, 3, 4]).
Can you get the rest right without peeking?
Take the timed Greedy Algorithms Quiz quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →