All practice tasks

Coding (Algo)

Find a Rank With Bounded Storage

Bounded heap · Medium

A telemetry collector needs the kth largest amount after reading a complete batch. It cannot reorder the supplied input and should retain only the leading k candidates. The answer counts duplicate positions rather than distinct values and is missing when the requested rank does not exist.

Return the kth largest value with duplicates counted as separate positions while using at most O(k) additional storage.

Input

Call

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

Input shape

{ nums: integer[], k: integer }

Fields

  • nums is the unsorted batch and k is a one-based descending rank.

Output

Return value

  • Return a single numeric value or null when k < 1 or k exceeds the number of entries.
  • This is one batch answer, not an array of prefix ranks. A value of zero or -1 is not an absence marker.

Constraints

  • 0 <= nums.length <= 100000; values are signed integers between -1000000000 and 1000000000.
  • -1 <= k <= 100001.

Examples

Example 1

{
  "k": 2,
  "nums": [
    9,
    9,
    3
  ]
}

Returns

9

Example 2

{
  "k": 3,
  "nums": [
    1,
    4
  ]
}

Returns

null

Required complexity

O(n log(k + 1)) time and O(k) auxiliary space for valid k

What this task practices

Find a Rank With Bounded Storage 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.