Friendship and Balance Tracker
Reported by candidates from Robinhood's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Example 2 in this Robinhood problem is the whole trap: two registered users, a transfer of 1, and the answer is REJECTED because they aren't friends. Robinhood candidates reported this one in September 2026. It's a stateful simulation, not an algorithm puzzle. You parse each operation string, keep a few hash maps, and return one result line per operation. The risk isn't difficulty, it's missing a rule on the way through. If you blank on the edge cases mid-assessment, StealthCoder runs invisibly on your desktop as a safety net, so you aren't stuck staring at the clock.
The problem
Process API-like operations in order. Each begins with a unique request id. id REGISTER user balance creates a user. id REQUEST from to creates a pending friend request stored under this id. id ACCEPT requestId accepts and consumes that pending request. id TRANSFER from to amount moves money only between accepted friends when the sender has enough balance. Return id OK for a successful non-transfer, id OK senderBalance receiverBalance for a successful transfer, or id REJECTED. Rejected operations do not change state. Function processFriendshipTransfers(operations: String[]) → String[] Examples Example 1 operations = ["1 REGISTER a 100","2 REGISTER b 0","3 REQUEST a b","4 ACCEPT 3","5 TRANSFER a b 30"] return = ["1 OK","2 OK","3 OK","4 OK","5 OK 70 30"] The accepted friendship authorizes the affordable transfer. Example 2 operations = ["r1 REGISTER a 10","r2 REGISTER b 0","r3 TRANSFER a b 1"] return = ["r1 OK","r2 OK","r3 REJECTED"] Registered users are not friends by default. Example 3 operations = ["1 REGISTER a 5","2 REGISTER a 9"] return = ["1 OK","2 REJECTED"] Duplicate registration is rejected without replacing the balance. Constraints 1 <= operations.length <= 2 * 10^5. Ids and usernames contain no spaces; request ids are unique. Balances and amounts fit signed 64-bit integers.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The pattern is simulation backed by hash tables. Keep a map of user to balance, a map of request id to (from, to) for pending requests, and a set of friend pairs. Store each pair in a normalized form, like sorted names, so friendship works both ways. The pitfalls are all in the rejection rules. REGISTER must reject duplicates without overwriting the balance. REQUEST should probably reject unknown users. ACCEPT must reject a missing or already consumed request id, then delete it. TRANSFER needs both users to exist, be friends, and the sender to have enough balance. Rejected operations must not mutate anything, so validate everything before you write. Balances are signed 64-bit, so watch overflow if your language needs it. With up to 2 * 10^5 operations, every step has to be O(1). If the live OA scrambles your memory of the rules, StealthCoder reads the statement and gives you a clean reference solution.
If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.
You can drill Friendship and Balance Tracker cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Robinhood's OA.
Robinhood reuses patterns across OAs. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Friendship and Balance Tracker FAQ
How hard is the Robinhood Friendship and Balance Tracker, really?+
Easy on algorithms, medium on care. There's no clever trick. You handle four operation types with hash maps and a set. Most failures come from missed rejection cases, not from complexity. Write the validations first, then mutate state only after every check passes.
What's the trick to this problem?+
Validate before you mutate. A rejected operation must leave state untouched, so check every condition first and update maps afterward. Also normalize friend pairs so a-b and b-a are the same entry. That covers most of the hidden tests.
What data structures should I use?+
A hash map from username to balance, a hash map from request id to a from/to pair, and a hash set of normalized friend pairs. All lookups are O(1), which matters with up to 2 * 10^5 operations in the input.
What edge cases should I test?+
Duplicate REGISTER, ACCEPT on an unknown or already used request id, TRANSFER between non-friends, transfers exceeding the sender's balance, and transfers to or from unregistered users. Also check that a consumed request can't be accepted twice.
How do I prepare for this in 48 hours?+
Practice parsing space-separated command strings and building small in-memory state machines. Write this exact problem once from scratch using the three examples as tests. Focus on clean rejection logic rather than any fancy algorithm, since that's where points get lost.