This question evaluates debugging skills and data-structure implementation competency, focusing on heap/priority-queue behavior, constructor initialization, and off-by-one indexing errors.
You are given a small codebase for selecting a dasher (driver) using a heap/priority-queue–like structure.
The current implementation is failing tests / behaving incorrectly. While debugging, you notice issues such as:
adjustKey()
has an
off-by-one
bug: it uses something like
size - 1
when
size
is already the correct last index (or vice versa).
If this were production code, what changes would you make beyond the minimal bug fix? Consider: