Simulate a PTO Accrual Ledger With Balance and Carryover Caps
Last updated: November 29, 2026
Quick Overview
Process a chronological stream of hours-worked, time-off requests and year-end events for one employee under a PTO policy with an accrual rate per hour, a maximum balance and a carryover cap, returning the final balance, a ledger and the rejected requests.
Gusto
November 29, 20260
0
0 solved
Process a chronological stream of hours-worked, time-off requests and year-end events for one employee under a PTO policy with an accrual rate per hour, a maximum balance and a carryover cap, returning the final balance, a ledger and the rejected requests.
Gusto lets employers configure PTO policies that accrue from hours on each payroll, and employees see the balance in their app. An onsite coding question in this style checks careful event ordering, capping rules and producing an auditable ledger rather than a single number.
What the Interviewer Expects
- Defines a deterministic order for same-day events
- Caps accrual at the max balance without going negative on accrual
- Rejects requests that exceed the allowed balance and records why
- Applies carryover forfeiture at year end
- Produces a ledger that explains every balance change
- Uses exact decimal arithmetic for fractional hours
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you recompute balances when a past payroll's hours are corrected?
- How would you support a policy that front-loads 80 hours on January 1 instead of accruing?
- Some states forbid forfeiting accrued vacation; how would the policy model express that?
- How would you store this so the employee app shows a balance instantly but history stays auditable?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Events are (date, kind, hours) with kind worked, request or year_end. Accrual is hours * rate, but the balance can never exceed max_balance, so accrual is clipped (hours past the cap are l...
High-Level Design
Sort events by date and then by a fixed kind order: hours worked on a day count before a request that day, and the year-end rollover runs last. Keep a running balance and append a ledger entry for eve...