JJobsMoi
Robinhood

Friends Money Transfer Request Processor

Coding

Problem

Problem Overview

Build a small payment system where users can sign up, become friends, and send money to each other. The input is a list of request strings. Process the requests in order, ignore invalid requests, and return every user's final balance.

This question is often framed as an OOD or clean-code coding round, but the important signal is still a complete working implementation with careful validation. The design should make it hard for unrelated code to mutate balances directly.

The core task is to parse request strings, maintain users, track pending friend requests, accept friendships, validate money transfers, and produce final balances after all valid requests have been applied.

Implement:

def process_requests(requests: list[str]) -> list[str]:
    pass

Common aliases:

  • Design a payment system
  • Friends money transfer system
  • OOP transfer system
  • Parse request strings and final balances

Request Format

Each request is a slash-delimited string. The first field is always the request ID, and the second field is the request type.

Use these request types:

<request_id>/signup/<user_id>/<initial_balance>
<request_id>/friend_req/<from_user>/<to_user>
<request_id>/friend_accept/<friend_request_id>
<request_id>/send_money/<from_user>/<to_user>/<amount>

Some reports mention five or six request types, but the preserved descriptions consistently identify these four core operations. If the interviewer adds another operation, handle it with the same parse-validate-mutate pattern.

Rules

  • A request ID that has already been successfully processed is invalid if it appears again.
  • signup creates a user with the given initial balance.
  • Duplicate users are invalid.
  • friend_req creates a pending friend request from one existing user to another existing user.
  • Users cannot friend themselves.
  • A friend request is invalid if the users are already friends or already have a pending request between them.
  • friend_accept receives the original friend request ID, not both user IDs.
  • Accepting a valid pending friend request creates an undirected friendship.
  • A friend request can only be accepted once.
  • send_money is valid only if both users exist, they are friends, the amount is positive, and the sender has enough balance.
  • Invalid requests do not change users, friendships, pending requests, or balances.
  • Return all signed-up users' final balances sorted by user ID.

For simplicity, amounts are non-negative integers, such as cents. If the interviewer uses decimal dollar amounts, parse them into integer cents before storing them.

Solution

Loading editor…

Sign in to get AI feedback on your answer. Your work is saved while you do.

Sign in to evaluate