Fewest Reward Credits for Raters Where Higher Scores Beat Neighbors

Last updated: November 29, 2026

Quick Overview

Raters stand in a line, each with a quality score. Every rater gets at least one credit, and any rater with a strictly higher score than an adjacent rater must get more credits than that neighbor. Return the minimum total credits.

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

0

0 solved


Raters stand in a line, each with a quality score. Every rater gets at least one credit, and any rater with a strictly higher score than an adjacent rater must get more credits than that neighbor. Return the minimum total credits.

A Google onsite greedy problem, framed around paying search quality raters with a fairness constraint relative to neighbors in a review queue. The interviewer wants the two-pass solution and a clear argument for why taking the max of the left and right constraints is both feasible and minimal.

What the Interviewer Expects
  • States both neighbor constraints separately
  • Uses a left-to-right pass for increasing runs
  • Uses a right-to-left pass and takes the max
  • Explains why the result is minimal
  • Mentions the O(1) space slope-counting variant
Key Topics to Cover
Greedy
Two Passes
Arrays
Local Constraints
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
  • Solve it in O(1) extra space.
  • What if the raters sit in a circle?
  • What if equal scores must also receive equal credits?
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 scores of integers, length n >= 1.
  • Output: minimum total of credits[i] with credits[i] >= 1, and credits[i] > credits[i-1] whenever scores[i] > scores[i-1] (and similarly for...
High-Level Design

Split the constraints by direction. Left pass: L[i] = L[i-1] + 1 if scores[i] > scores[i-1], else 1. This is the minimum needed to satisfy only left neighbors. Right pass: R[i] = R[i+1] + 1 if `...


Submit Your Answer
Markdown supported