All practice tasks

Coding (Algo)

Account Ledger Totals

Hash map · Easy

A ledger export contains signed integer-cent adjustments. A report needs one balance per account.

Sum adjustments per account and return accounts in ASCII order.

Input

Call

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

Input object

{ entries:{account:string,cents:integer}[] }

What each field means

  • entries — ledger adjustments. account identifies the account; signed cents adds to or subtracts from its balance.

Output

Return value and rules

  • Return one {account, cents} total per account that appeared.
  • Include accounts whose adjustments sum to zero.
  • Sort accounts by ASCII ID ascending.

Constraints

  • 0 <= entries.length <= 100000
  • Account IDs contain 1–40 lowercase ASCII letters; cents in [-1000000,1000000].

Examples

Example 1

{
  "entries": [
    {
      "account": "b",
      "cents": 5
    },
    {
      "account": "a",
      "cents": 3
    },
    {
      "account": "b",
      "cents": -2
    }
  ]
}

Returns

[
  {
    "account": "a",
    "cents": 3
  },
  {
    "account": "b",
    "cents": 3
  }
]

Example 2

{
  "entries": []
}

Returns

[]

Required complexity

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

What this task practices

Account Ledger Totals 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.