List Every Valid Order to Run Onboarding Steps
Last updated: November 29, 2026
Quick Overview
A new user onboarding flow has n steps and constraints [a, b] meaning step a must come before step b. Return all orderings of the steps that satisfy every constraint, so product can review each possible flow.
Meta
November 29, 20260
0
0 solved
A new user onboarding flow has n steps and constraints [a, b] meaning step a must come before step b. Return all orderings of the steps that satisfy every constraint, so product can review each possible flow.
A Meta technical screen variant that pairs topological sort with backtracking, framed around enumerating the possible orders for a Facebook or Instagram new-user onboarding flow. The interviewer checks that you backtrack over Kahn's available set, undo in-degree changes correctly, and understand that the output can be exponential.
What the Interviewer Expects
- Backtrack by choosing any currently available step
- Restore in-degrees and the used flag when undoing a choice
- Recognize the output size can be up to n factorial
- Return an empty list when constraints contain a cycle
- Keep the code free of shared-state bugs
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you count the orders without listing them?
- How would you return only the k orders that minimize some cost?
- Can you sample a uniformly random valid order?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- Input:
nsteps0..n-1andconstraints[a, b]. - Output: every permutation consistent with all constraints, in any order.
nis small (up to about 10), since the answer itself can be huge....
High-Level Design
Every valid order is produced by some sequence of choices in Kahn's algorithm: at each position, pick any step that is unused and has in-degree zero. Backtracking explores all of those choice sequence...