All practice tasks

Coding (Algo)

Affordable Replay Window

Sliding window · Medium

A mobile client replays a contiguous section of queued actions while keeping total transfer size within a budget.

Return the longest contiguous window whose total size is at most budget.

Input

Call

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

Input object

{ sizes:integer[], budget:integer }

Input rules

  • Sizes are non-negative and may be zero.

What each field means

  • sizes — non-negative replay sizes in their original order.
  • budget — maximum combined size of the selected consecutive window.

Output

Return value and rules

  • Return the largest number of consecutive entries whose sum does not exceed the budget.
  • You may not skip entries inside the window. Zero-size entries still count toward its length.
  • Empty input returns 0.

Constraints

  • 0 <= sizes.length <= 100000; 0 <= size <= 1000000
  • 0 <= budget <= 100000000000. A subsequence that skips actions is invalid.

Examples

Example 1

{
  "budget": 4,
  "sizes": [
    2,
    1,
    3,
    1
  ]
}

Returns

2

Example 2

{
  "budget": 0,
  "sizes": []
}

Returns

0

Required complexity

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

What this task practices

Affordable Replay Window 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.