Build the Approval Chain for a Purchase Request
Last updated: November 29, 2026
Quick Overview
Given a purchase request (requester, department, category, amount) and an ordered list of routing rules, return the ordered, de-duplicated list of approvers the request must go through. A requester never approves their own request.
ZipHQ
November 29, 20260
0
0 solved
Given a purchase request (requester, department, category, amount) and an ordered list of routing rules, return the ordered, de-duplicated list of approvers the request must go through. A requester never approves their own request.
Zip's core product routes every purchase request through approvers chosen by configurable rules such as amount thresholds and category. A phone screen version of that checks whether you can turn fuzzy business rules into clean, predictable code and ask the right questions about boundaries.
What the Interviewer Expects
- Clarify whether thresholds are inclusive or exclusive and whether rule order matters
- Filter rules with optional conditions without special-casing every field
- Preserve first-seen order while removing duplicate approvers
- Exclude the requester from their own chain
- State complexity and discuss how rules would be stored per customer
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 support approvers that are roles ("department head") resolved at runtime?
- What if two rules conflict, for example one says skip finance under $1k?
- How would you explain to an admin why a given approver was added?
- How do you handle a chain that ends up empty?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Each rule has optional department, category, min_amount (inclusive) and max_amount (exclusive) plus a list of approvers. A rule applies when every condition it specifies matches. Output appr...
High-Level Design
Walk the rules once. For each rule, check each present condition; skip on the first mismatch. For matching rules, append approvers not already seen. A set gives O(1) duplicate checks and a list preser...