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
Coding & Algorithms
Software Engineer
Amazon
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

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
greedy
two-pass scan
local constraints
arrays
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample 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...


Submit Your Answer
Markdown supported