FastPrepFriendship and Balance Tracker
Problems/Friendship and Balance Tracker

Friendship and Balance Tracker

Robinhood logoRobinhood● MediumFULLTIMEONSITE INTERVIEW
QuestionFunctionExamplesConstraints

Problem statement

Source note: The report names the recurring Robinhood friendship/money-transfer task. A focused public lookup in the in-app browser corroborated the stable operations: registration, request-by-id acceptance, friendship-gated transfers, and balance checks. The portable line encoding and exact response text are assumptions; match is about 91%.

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.

More Robinhood problems

  • Top Ten Most Frequent Words in a BookPHONE SCREEN · Seen Oct 2026
  • Fractional Share Inventory FlatteningPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Unique Transitive Dependent CountsPHONE SCREEN · Seen Sep 2026
All Robinhood interview questionsSee Robinhood hiring insights
Saved
class Solution {
    public String[] processFriendshipTransfers(String[] operations) {
        // Write your solution here.
    }
}
Checking account…