Order Validator Rule DAG
Updated
Problem statement
Process the commands in order. They work on a set of rules that depend on each other (a DAG, which is a graph with no cycles).
ADD|id|field|min|depsadds a rule. Use-when the rule has no dependencies.REMOVE|idremoves a rule and rewires the rules that depended on it.VALIDATE|v0,v1,...checks the rules in lexicographically stable topological order. In this order, a rule is always checked after the rules it depends on.
For each command, return one of ADDED, CYCLE, EXISTS, REMOVED, NOT_FOUND, VALID, or INVALID:id.
A rule passes only when the values list has an entry at its field position, and that entry is at least the rule's minimum. INVALID:id names the first rule that fails in that order.
Function
runOrderValidator(operations: String[]) → String[]Examples
Example 1
operations = ["ADD|A|0|5|-","ADD|B|1|2|A","VALIDATE|5,2"]return = ["ADDED","ADDED","VALID"]Sequence 1: both rules are added. Rule A needs the value at field zero to be at least five, and the first value is five. Rule B needs field one to be at least two, and the second value is two. Both pass, so the result is VALID.
Example 2
operations = ["ADD|A|0|5|-","VALIDATE|4"]return = ["ADDED","INVALID:A"]Sequence 2: rule A needs the value at field zero to be at least five, but the value is four. The check fails at rule A, so the result is INVALID:A.
Constraints
1 <= operations.length <= 2000- Rule IDs contain letters and digits only.
- Field indices and minimum values are nonnegative integers.
- Dependencies absent from the active rule set are ignored until their rule is added.
More ByteDance Phone Screen questions
- Course SchedulePHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
- Implement QuicksortPHONE SCREEN · Seen Dec 2026
- Largest Rectangle in HistogramPHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
- Reverse Linked ListPHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
- Count N-Queens PlacementsPHONE SCREEN · Seen Nov 2026
- Matrix EscapePHONE SCREEN · Seen Nov 2026
- Largest Number Below N from Reusable DigitsPHONE SCREEN · Seen Nov 2026
- Log Analyzer: Busiest Service in a Rolling WindowPHONE SCREEN · Seen Nov 2026
- Majority ElementPHONE SCREEN · Seen Nov 2026
- Valid ParenthesesPHONE SCREEN · Seen Nov 2026
Similar questions at other companies
- Spreadsheet Formula EvaluatorHarvey · PHONE SCREEN · ONSITE INTERVIEWHarvey interview questions
- Durable Work Queue with DependenciesOpenAI · PHONE SCREENOpenAI interview questions
- Course Ordering with Concurrent UpdatesNuro · PHONE SCREENNuro interview questions
- Task Scheduler with Prerequisites and Execution PathsBrex · PHONE SCREEN
- Corporation Reporting LinesMicrosoft · PHONE SCREENMicrosoft interview questions
- Priority-Aware Dependent Task OrderGoogle · ONSITE INTERVIEWGoogle interview questions
- Out-of-Order Loan LedgerValon · PHONE SCREEN
- Design In-Memory File SystemSnowflake · PHONE SCREENSnowflake interview questions
- Delivery Cost Tracker with Effective-Dated RatesRippling · PHONE SCREENRippling interview questions
- Select Transactions with Child-Pays-for-Parent PackagesCoinbase · PHONE SCREENCoinbase interview questions
ByteDance interview experiences
- ByteDance TikTok USDS SWE Intern Interview: 1 Experience
- ByteDance MLE New Grad Interviews: 1 Experience
- ByteDance Security SRE Intern Phone Screens: 1 Experience
- ByteDance USDS New Grad SWE Phone Screen: 1 Experience
- ByteDance New Grad Data Engineer Video Interviews: 1 Experience
- ByteDance Trust & Safety Research Scientist Intern: 1 Experience