All practice tasks

Coding (Algo)

Find the Next Higher Reading

Monotonic stack · Medium

A monitoring chart annotates each recorded measurement with the first later reading that exceeds it. Equal readings do not end the wait, and the annotation needs the later value rather than its index or the largest value in the suffix.

Return the first strictly higher value to the right of each measurement and null when no such value exists.

Input

Call

  • Implement solve(input) and return the result. The provided adapter handles JSON input and output.

Input shape

{ nums: integer[] }

Fields

  • nums lists signed measurements in time order.

Output

Return value

  • Return an array of the same length, aligned with the original indexes. Use null when there is no strictly greater reading.
  • A later value of -1 is an ordinary answer, not an absence marker.

Constraints

  • 0 <= nums.length <= 100000; each value is an integer between -1000000000 and 1000000000.

Examples

Example 1

{
  "nums": [
    2,
    2,
    3,
    1
  ]
}

Returns

[
  3,
  3,
  null,
  null
]

Example 2

{
  "nums": [
    -2,
    -1
  ]
}

Returns

[
  -1,
  null
]

Required complexity

O(n) time and O(n) auxiliary space

What this task practices

Find the Next Higher Reading is a coding (algo) interview exercise that trains prompt interpretation, explicit assumptions, a concrete response, and a clear explanation of tradeoffs. The catalog marks it as medium difficulty. It focuses on Technical Reasoning, Testing, Validation. The signed-in workspace provides the tools for the round and evaluates the attempt against task-specific criteria. Reference solutions, hidden checks, evaluator instructions, and candidate work remain private.

Sign in to startThe workspace and evaluation open after sign in.