Replay Loan Application Events Through a State Machine

Last updated: November 29, 2026

Quick Overview

Given a possibly out-of-order list of (application_id, timestamp, new_state) events and a table of allowed transitions, replay them in time order and return each application's final state plus the list of events that were rejected as invalid transitions.

SoFi
Coding & Algorithms
Software Engineer
SoFi
November 29, 2026
Software Engineer
Online Assessment
Coding & Algorithms
Easy

0

0

0 solved


Given a possibly out-of-order list of (application_id, timestamp, new_state) events and a table of allowed transitions, replay them in time order and return each application's final state plus the list of events that were rejected as invalid transitions.

SoFi's personal, student and home loan flows move applications through states like underwriting, needs documents, approved and funded. This assessment style problem checks that you model the transitions as data, process events deterministically, and treat bad events as data to report rather than crashes.

What the Interviewer Expects
  • Represents allowed transitions as a dict of sets instead of nested if statements
  • Sorts by timestamp with a stable sort so ties keep arrival order
  • Requires the first event for an application to be SUBMITTED
  • Leaves state unchanged on a rejected event and records it
  • Treats terminal states as having no outgoing transitions
Key Topics to Cover
state machines
event sourcing
stable sorting
validation
hash sets
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How would you make replay idempotent if the same event is delivered twice?
  • What would you store so support can explain why an application is stuck?
  • How would you add a timeout rule such as auto-withdraw after 30 days in NEEDS_DOCS?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

States: SUBMITTED, UNDERWRITING, NEEDS_DOCS, APPROVED, DECLINED, WITHDRAWN, FUNDED. Events can arrive out of order from different services. Apply them in timestamp order; an event is valid only if it ...

High-Level Design

Keep the transition table as data so product can change it without touching control flow. Keep a dict app_id -> current_state. Sort all events by timestamp once, then fold over them. Python's sort i...


Submit Your Answer
Markdown supported

Related Questions