Minimum Bonus Credits for Drivers Rated Higher Than Their Neighbors
Last updated: November 29, 2026
Quick Overview
Delivery drivers stand in a line with ratings r[i]. Each driver gets at least one bonus credit, and any driver rated higher than an adjacent driver must get more credits than that neighbor. Return the minimum total credits.
Amazon
November 29, 20260
0
0 solved
Delivery drivers stand in a line with ratings r[i]. Each driver gets at least one bonus credit, and any driver rated higher than an adjacent driver must get more credits than that neighbor. Return the minimum total credits.
An Amazon onsite greedy question about local constraints with a global minimum. The interviewer wants the two-pass approach and a clear argument that taking the max of the left and right requirements is both necessary and sufficient.
What the Interviewer Expects
- Separates the left-neighbor and right-neighbor constraints
- Does a left-to-right then right-to-left pass
- Takes the max at each position
- Argues minimality
- Handles equal adjacent ratings (no constraint)
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Can you do it in O(1) extra space?
- What if drivers are arranged in a circle?
- What if the constraint applies to a 2D grid of neighbors?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: list of ratings, length n >= 1. Output: minimum sum of credits c[i] >= 1 with c[i] > c[i - 1] when r[i] > r[i - 1], and c[i] > c[i + 1] when r[i] > r[i + 1]. Equal ratings impose nothing....
High-Level Design
The constraints split into two independent chains. Left pass: left[i] = left[i - 1] + 1 if r[i] > r[i - 1], else 1; this is the smallest assignment satisfying only the left-neighbor rules. Right pas...