All practice tasks

Coding (Algo)

Duration Buckets

Hash map · Easy

An ingestion API summarizes non-negative durations into fixed-width histogram buckets.

Return only occupied buckets sorted by bucket number.

Input

Call

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

Input object

{ durations:integer[], width:integer }

Input rules

  • Bucket index is floor(duration/width).

What each field means

  • durations — non-negative duration measurements.
  • width — the size of each bucket. Duration d belongs to bucket floor(d / width).

Output

Return value and rules

  • Return {bucket, count} objects for occupied buckets only.
  • Order the objects by bucket number ascending.
  • Empty measurements return [].

Constraints

  • 0 <= durations.length <= 100000; duration in [0,1000000000]
  • 1 <= width <= 1000000

Examples

Example 1

{
  "durations": [
    0,
    9,
    10,
    20
  ],
  "width": 10
}

Returns

[
  {
    "bucket": 0,
    "count": 2
  },
  {
    "bucket": 1,
    "count": 1
  },
  {
    "bucket": 2,
    "count": 1
  }
]

Example 2

{
  "durations": [],
  "width": 1
}

Returns

[]

Required complexity

O(n + b log b) time and O(b) space

What this task practices

Duration Buckets 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.