Order Underwriting Checks With Dependencies Deterministically

Last updated: November 29, 2026

Quick Overview

Underwriting a loan runs checks such as KYC, credit pull, fraud screening and income verification, some of which depend on others. Given the steps and dependency pairs, return a valid execution order that is lexicographically smallest, or an empty list if the dependencies contain a cycle.

SoFi
Coding & Algorithms
Software Engineer
SoFi
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

0

0 solved


Underwriting a loan runs checks such as KYC, credit pull, fraud screening and income verification, some of which depend on others. Given the steps and dependency pairs, return a valid execution order that is lexicographically smallest, or an empty list if the dependencies contain a cycle.

SoFi's lending stack orchestrates many underwriting checks across services, and a config change that introduces a cycle should be caught before deploy. The interviewer checks Kahn's algorithm, cycle detection, and why a heap makes the output deterministic for testing and audit logs.

What the Interviewer Expects
  • Builds an adjacency list and in-degree map
  • Uses Kahn's algorithm with a min-heap for the lexicographic tie-break
  • Detects a cycle by comparing output length to the number of steps
  • Includes steps with no dependencies
  • States O((V + E) log V) complexity
Key Topics to Cover
topological sort
Kahn's algorithm
heaps
cycle detection
workflow orchestration
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 return the steps that participate in the cycle?
  • How would you compute which checks can run in parallel and the minimum number of stages?
  • What if each step has a duration and you want the earliest finish time?
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

Steps are unique names; (before, after) means before must finish first. Return the lexicographically smallest topological order so the same config always produces the same order, or [] if no val...

High-Level Design

Kahn's algorithm repeatedly takes a step with in-degree zero. Using a min-heap of ready steps instead of a queue means that whenever several steps are ready we pick the smallest name, which yields the...


Submit Your Answer
Markdown supported