All practice tasks

Coding (Algo)

Find the Lowest Reading in Each Period

Segment tree · Medium

An incident report highlights the lowest observed reading in each selected period. It may ask about many overlapping periods in one fixed snapshot. The implementation must reuse an index rather than scanning all readings for every selection.

Return the minimum numeric reading for every requested inclusive period without changing the snapshot.

Input

Call

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

Input shape

{ nums: integer[], queries: [integer, integer][] }

Fields

  • nums contains signed integer readings in observation order.
  • queries is an array of inclusive zero-based [left,right] index pairs. Every pair satisfies 0 <= left <= right < nums.length.
  • The values do not change between queries. If nums is empty, queries is empty. Neither input array may be modified.

Output

Return value

  • Return minimum values, not positions, in query order. Equal minima do not require a tie-break.
  • A single-position query returns that value. Empty queries return [].

Constraints

  • 0 <= nums.length <= 100000; 0 <= queries.length <= 100000.
  • All input indexes and counts are integers.
  • -1000000000 <= nums[i] <= 1000000000.

Examples

Example 1

{
  "nums": [
    8,
    -2,
    5,
    1
  ],
  "queries": [
    [
      0,
      0
    ],
    [
      1,
      3
    ],
    [
      2,
      3
    ]
  ]
}

Returns

[
  8,
  -2,
  1
]

Example 2

{
  "nums": [
    6,
    6
  ],
  "queries": [
    [
      0,
      1
    ]
  ]
}

Returns

[
  6
]

Required complexity

O(n) index construction and O(log(n + 1)) per query with O(n) auxiliary space

What this task practices

Find the Lowest Reading in Each Period 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.