All practice tasks

Coding (Algo)

Peak Request Latency

Stable ordering · Easy

A batch of request timings is sampled in arrival order. The dashboard needs the earliest request with the worst latency.

Return the index of the largest latency, preferring the earliest on ties.

Input

Call

  • Implement solve(input) and return its result. Do not print from solve.

Input object

{ latencies:integer[] }

What each field means

  • latencies — request durations in batch order.

Output

Return value and rules

  • Return the zero-based index of the largest latency.
  • If the maximum occurs several times, return its earliest index.
  • Return -1 for an empty batch.

Constraints

  • 0 <= latencies.length <= 100000
  • 0 <= latency <= 1000000000

Examples

Example 1

{
  "latencies": [
    3,
    9,
    9,
    1
  ]
}

Returns

1

Example 2

{
  "latencies": []
}

Returns

-1

Required complexity

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

What this task practices

Peak Request Latency 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 easy 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.