Skip to the code
cf.
+50 XP

#596 Fewest Reward Points for Reviewers

hard

A code review leaderboard shows reviewers in a row with their quality scores, scores. Each reviewer gets a whole number of reward points with two rules: everyone gets at least 1 point, and a reviewer with a strictly higher score than a neighbor next to them in the row must get more points than that neighbor.

Write fewestPoints(scores) that returns the smallest total number of points that follows both rules.

Example 1

Input: scores = [1,0,2]
Output: 5

Give 2, 1, 2 points.

Example 2

Input: scores = [1,2,2]
Output: 4

Give 1, 2, 1: the last reviewer ties with their neighbor, so 1 point is enough.

Constraints

  • 0 <= scores.length <= 100000
  • 0 <= scores[i] <= 10^4
Saved in this browser

Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.

Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).