All practice tasks

Coding (Algo)

Measure the Current High Span

Monotonic stack · Medium

A monitoring chart annotates each measurement with the consecutive period ending there during which no reading exceeded the current value. The period always includes the current reading and stops at the nearest earlier greater value.

Return the length of that ending period for every measurement in the supplied stream.

Input

Call

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

Input shape

{ nums: integer[] }

Fields

  • nums is an array of signed integers in its original order. Equal values at different indexes are separate entries.

Output

Return value

  • Return one positive integer span per input value. Empty input returns [].
  • Equal earlier values extend the span. Stop at a strictly greater reading; do not skip it.

Constraints

  • 0 <= nums.length <= 100000; -1000000000 <= nums[i] <= 1000000000.
  • All requested totals and counts fit exactly in a safe JSON integer.

Examples

Example 1

{
  "nums": [
    5,
    3,
    3,
    6
  ]
}

Returns

[
  1,
  1,
  2,
  4
]

Example 2

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

Returns

[
  1,
  1,
  1
]

Required complexity

O(n) time and O(n) space

What this task practices

Measure the Current High Span 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.