Validate and Complete Racer Precedence
Updated
Problem statement
Each pair [before,after] states that racer before finished ahead of racer after. Racer names are the names appearing in at least one pair.
Return four strings: whether the data is acyclic, whether it determines one complete total order, the first racer, and the last racer. Boolean fields are "true" or "false". If the data is cyclic or does not determine a unique total order, return empty strings for first and last. Duplicate relations do not change the result.
Function
analyzeRaceOrder(relations: String[][]) → String[]Examples
Example 1
relations = [["A","B"],["B","C"],["C","D"]]return = ["true","true","A","D"]The DAG has one topological order from A to D.
Example 2
relations = [["A","C"],["B","C"]]return = ["true","false","",""]The data is valid but A and B are incomparable.
Example 3
relations = [["A","B"],["B","A"]]return = ["false","false","",""]The cycle makes the data invalid.
Constraints
0 <= relations.length <= 100000.- Names are nonempty.
More Microsoft Onsite Interview questions
- Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2026
- Valid ParenthesesONSITE INTERVIEW · Seen Nov 2026
- Count a User's Actions in an Event LogONSITE INTERVIEW · Seen Nov 2026
- Smallest Batch Size Within a Step LimitONSITE INTERVIEW · Seen Nov 2026
- Count Subarrays with Equal Even and Odd CountsONSITE INTERVIEW · Seen Nov 2026
- Minimum Time to Rot All OrangesONSITE INTERVIEW · Seen Nov 2026
- Coin ChangeONSITE INTERVIEW · Seen Oct 2026
- Daily USD Totals with Effective-Dated Exchange RatesONSITE INTERVIEW · Seen Oct 2026
- Number Words to Digits in Any LanguageONSITE INTERVIEW · Seen Oct 2026
- Totals from a Tiered Rate TableONSITE INTERVIEW · Seen Oct 2026
Similar questions at other companies
- Evaluate Formulas with Cycle DetectionInstacart · PHONE SCREEN · ONSITE INTERVIEWInstacart interview questions
- Can Subsequences Share One Master Sequence?Google · ONSITE INTERVIEWGoogle interview questions
- Password From Ordering HintsRogo · ONSITE INTERVIEW
- Alien DictionaryByteDance · PHONE SCREEN · ONSITE INTERVIEWByteDance interview questions
- Alien DictionaryBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions
- Alien DictionaryAmazon · ONSITE INTERVIEW
- Letter Order from a Sorted Word ListRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions
- Validate CSV References and Field DependenciesStripe · PHONE SCREENStripe interview questions
- Alien DictionaryIntuit · OAIntuit interview questions
- Recover an Alien Alphabet from Sorted WordsOpenAI · PHONE SCREENOpenAI interview questions
Interview reports that mention this question
Microsoft interview experiences
- Microsoft Explore and Student SWE: 12 Experiences (Part 6 of 6)
- Microsoft SWE Intern, Early 2025: 41 Experiences (Part 5 of 6)
- Microsoft SWE Intern, Mid 2025: 42 Experiences (Part 4 of 6)
- Microsoft SWE Intern, Late 2025: 47 Experiences (Part 3 of 6)
- Microsoft SWE Intern, Early 2026: 54 Experiences (Part 2 of 6)