2. Next Bigger Over

MediumMonotonic StackStackArray
LC 739: Daily Temperatures

You are analyzing the scoring momentum of a T20 or ODI innings. You are given an integer array overs, where overs[i] is the total number of runs scored in the i-th over.

Return an integer array answer of the same length, where answer[i] is the number of overs you have to wait after over i until the batting team scores strictly more runs in a single over.

If there is no future over with strictly more runs than overs[i], set answer[i] = 0.

Example 1 — Momentum Shifts

Input:  overs = [6, 12, 8, 9, 15, 4, 18, 10]
Output: [1, 3, 1, 1, 2, 1, 0, 0]
Explanation:
- Over 0 (6 runs)  -> Over 1 (12 runs): wait 1 over
- Over 1 (12 runs) -> Over 4 (15 runs): wait 3 overs
- Over 2 (8 runs)  -> Over 3 (9 runs):  wait 1 over
- Over 6 (18 runs) -> No bigger over follows: 0

Example 2 — Death-Over Acceleration

Input:  overs = [4, 8, 12, 16, 22]
Output: [1, 1, 1, 1, 0]
Explanation: Every over improves on the previous one until the final over.

Example 3 — Choked Innings (Equal Overs Don't Count)

Input:  overs = [18, 14, 14, 10, 6, 0]
Output: [0, 0, 0, 0, 0, 0]
Explanation: Runs never strictly increase (14 is equal to 14, not strictly greater).

Constraints

  • 1 <= len(overs) <= 10^5
  • 0 <= overs[i] <= 36 (maiden over up to six sixes in an over)
  • Target Complexity: O(N) time, O(N) space.

Progressive Hints

Tip: Switch to desktop for the best coding experience — problem descriptions and explainer videos work great on mobile.
Loading code editor...
Test Cases
Ctrl+Enter Run · Ctrl+Shift+Enter Submit
Case 1: 19th-Over 36-Run Explosion (IND vs ENG, 2007)ESPNcricinfo Scorecard · IND vs ENG (2007)
Not run yet
Input: overs = [8, 10, 12, 6, 9, 36, 11]
Expected: [1,1,3,1,1,0,0]