All practice tasks

Coding (Algo)

Ledger Prefix Balances

Prefix sum · Easy

A statement screen needs the balance after every signed transaction, starting from an opening balance.

Return the running balance after each adjustment.

Input

Call

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

Input object

{ opening:integer, adjustments:integer[] }

What each field means

  • opening — balance before any transaction.
  • adjustments — signed amounts to apply in order.

Output

Return value and rules

  • Return the running balance after each adjustment.
  • Do not include opening as a separate result element.
  • No adjustments produce [].

Constraints

  • 0 <= adjustments.length <= 100000
  • Opening and adjustments are in [-1000000,1000000]; totals fit a safe integer.

Examples

Example 1

{
  "adjustments": [
    3,
    -5,
    0
  ],
  "opening": 10
}

Returns

[
  13,
  8,
  8
]

Example 2

{
  "adjustments": [],
  "opening": 5
}

Returns

[]

Required complexity

O(n) time and O(n) output space

What this task practices

Ledger Prefix Balances 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.