Scheduled Payments with Account Aliases
Updated
Problem statement
You are given the starting account names accounts and a list of operations. Run the operations in order on a small ledger of scheduled payments and accounts. The ledger only tracks what happens to each payment and which names belong to which account. It does not track balances or move money.
At the start, each name in accounts is its own active account, and the names are unique. There are no payments, and the processing clock is at zero.
Accounts can be merged into groups. Each active group has one main name, called its canonical name. Every other name in the group is an alias of it. A name resolves to the active group it belongs to. A retired or unknown name does not resolve.
Operations
["SCHEDULE", paymentId, account, dueTime]: create a pending payment for the active group thataccountresolves to. This works only if the name resolves, the ID has never been used, anddueTimeis at least the processing clock. ReturnTRUEon success, otherwiseFALSE.["CANCEL", paymentId]: if the payment is pending, cancel it and returnTRUE. ReturnFALSEif the payment does not exist, or was already processed or cancelled.["STATUS", paymentId]: returnPENDING,PROCESSED,CANCELLEDorNOT_FOUND.["PROCESS_DUE", time]: move the processing clock totime. Then process every payment that is still pending and has a due time at most the clock. Return their IDs joined by commas, sorted by due time. Payments with the same due time keep the order they were scheduled in. ReturnEMPTYwhen nothing is processed.["MERGE", source, target]: move the active group thatsourceresolves to into the different active group thattargetresolves to. Every name from the source group becomes an alias of the target's canonical name. Pending payments move with the group. ReturnTRUE. ReturnFALSEif either name does not resolve, or both already resolve to the same group.["RETIRE", account]: retire the active group thataccountresolves to. Every name in that group stops resolving, and all of the group's pending payments are cancelled. ReturnTRUE, orFALSEwhen the name already does not resolve.["RESOLVE", account]: return the canonical name of the active group thataccountresolves to, orNOT_FOUND.
Only PROCESS_DUE processes payments. A payment scheduled at the current clock stays pending until the next such call. Processing calls never go back in time. A cancelled or processed payment ID can never be used again. Once a payment is processed or cancelled, its status never changes. A merge keeps the target group's canonical name and does not create a new account. Retiring a group does not change payments that were already processed.
Return one string for each operation, in order.
Function
runPaymentLedger(accounts: String[], operations: String[][]) → String[]Examples
Example 1
accounts = ["a","b","c"]operations = [["SCHEDULE","p1","a","5"],["MERGE","a","b"],["RESOLVE","a"],["PROCESS_DUE","5"],["STATUS","p1"],["CANCEL","p1"]]return = ["TRUE","TRUE","b","p1","PROCESSED","FALSE"]Payment p1 is scheduled on a. Merging a into b makes a an alias of b, so RESOLVE returns b and p1 moves with the group. PROCESS_DUE runs at exactly the due time of p1, which counts as due, so it returns p1. Its status is now PROCESSED, so cancelling it fails and returns FALSE.
Example 2
accounts = ["a","b","c"]operations = [["SCHEDULE","p1","a","2"],["SCHEDULE","p2","b","2"],["RETIRE","a"],["STATUS","p1"],["PROCESS_DUE","2"],["RESOLVE","a"]]return = ["TRUE","TRUE","TRUE","CANCELLED","p2","NOT_FOUND"]Both payments are scheduled. Retiring a cancels its pending payment p1, so its status is CANCELLED. Payment p2 on b is not touched, so PROCESS_DUE returns only p2. The name a no longer resolves, so RESOLVE returns NOT_FOUND.
Example 3
accounts = ["a","b","c"]operations = [["SCHEDULE","later","c","7"],["SCHEDULE","first","a","3"],["SCHEDULE","second","b","3"],["CANCEL","first"],["PROCESS_DUE","7"],["SCHEDULE","later","a","8"]]return = ["TRUE","TRUE","TRUE","TRUE","second,later","FALSE"]Three payments are scheduled, then first is cancelled. PROCESS_DUE skips it and handles the two still pending by due time. second is due before later, so the result is second,later. Scheduling later again fails because that payment ID was already used, so it returns FALSE.
Constraints
1 <= accounts.length <= 1000and1 <= operations.length <= 1000.- Starting account names are unique. Account names and payment IDs are nonempty and use only lowercase letters or digits, with at most
20characters. - Every operation has one of the shapes listed above. Due times and processing times are decimal integers in
[0, 1000000000]. - Processing times never go down. Other operations do not move the processing clock.
- A name in an operation may be unknown. A retired name never becomes active again.
More Coinbase interview questions
- Dynamic Fixed-K Score LeaderboardONSITE INTERVIEW · Seen Aug 2026
- Minimum Days for Fixed-Order Tasks with CooldownONSITE INTERVIEW · Seen Aug 2026
- Sliding-Window Averages as Reduced FractionsONSITE INTERVIEW · Seen Aug 2026
- Parse and Order Structured LogsONSITE INTERVIEW · Seen Aug 2026
- Select Transactions with Child-Pays-for-Parent PackagesPHONE SCREEN · Seen Oct 2026
- Task Management SystemOA · Seen Sep 2026
- Cloud Compute Credits SystemOA · Seen Aug 2026
- Banking System with Historical SnapshotsOA · Seen Aug 2026
- Find the Length of the Longest Common PrefixOA · Seen Oct 2024
- Lexicographically Smallest Topological OrderPHONE SCREEN · Seen Apr 2022
Similar questions at other companies
- 15-Minute Chat Session TrackerOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
- LRU Cache with TTLAutodesk · ONSITE INTERVIEWAutodesk interview questions
- Keyed Bounded Executor ScheduleMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Tiered Expiring Item StoreHudson River Trading · PHONE SCREEN · ONSITE INTERVIEWHudson River Trading interview questions
- Limit Order Book Matching EngineCitadel · PHONE SCREEN · ONSITE INTERVIEWCitadel interview questions
- Live Top-K Spaces by Active UsersxAI · ONSITE INTERVIEWxAI interview questions
- Expiring Key SetAmazon · ONSITE INTERVIEW
- Design Authentication ManagerOracle · ONSITE INTERVIEWOracle interview questions
- Ad Score Scheduler With DelayGoogle · ONSITE INTERVIEWGoogle interview questions
- Thread-Safe Task Storage and Worker DispatchNuro · ONSITE INTERVIEWNuro interview questions