Skip to the code
+10 XP

#262 Next Larger Badge Count

easy

A notification bell logs its badge count after every update in counts. For each update, the analytics team wants the first later count that is strictly larger.

Write nextLarger(counts) that returns an array where position i holds the first value after index i that is greater than counts[i], or -1 if no later value is greater.

Example 1

Input: counts = [2,1,5,3,4]
Output: [5,5,-1,4,-1]

2 and 1 are first beaten by 5; 3 by 4; nothing beats 5 or 4.

Example 2

Input: counts = [4,4,4]
Output: [-1,-1,-1]

Equal counts are not larger.

Constraints

  • 0 <= counts.length <= 2 * 10^5
  • 0 <= counts[i] <= 10^9
Saved in this browser

Run tries your code on the examples. Submit runs every test, including hidden edge cases and big inputs that check your code is fast enough, and solves the problem when they all pass.

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