Transitive Greater-Than Relation Queries
Updated
Problem statement
You are given a list relations. Each pair [a,b] in it is a fact that means a > b. The facts never form a loop, so no chain of facts leads from a number back to itself.
Facts chain together: if a is greater than b and b is greater than c, then a is greater than c. For each query [x,y], return GREATER if a chain of facts shows x>y, LESS if a chain shows y>x, and UNKNOWN if no chain decides it.
Function
resolveRelations(relations: int[][], queries: int[][]) → String[]Examples
Example 1
relations = [[1,2],[1,4],[4,7],[7,5]]queries = [[1,5],[5,1],[2,4]]return = ["GREATER","LESS","UNKNOWN"]Following the facts from 1 leads to 5, so the first query gives GREATER. The second query asks about the same pair the other way round, so it gives LESS. No chain connects 2 and 4 in either direction, so the last query gives UNKNOWN.
Constraints
- At most
10^5relations and queries.
More Bloomberg LP Onsite Interview questions
- Pascal's TrianglePHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
- Valid Triangle NumberPHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
- Collatz Conjecture with Shared MemoizationPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Word SearchOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- N-ary Index-Path Encoder and DecoderPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Top K Frequent WordsONSITE INTERVIEW · Seen Nov 2026
- Trapping Rain WaterPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Design Browser HistoryPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Mutable Stock Price Top KPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Add Two Numbers IIPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
Similar questions at other companies
- Course ScheduleAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Course ScheduleOracle · ONSITE INTERVIEWOracle interview questions
- Package Install OrderVerily · ONSITE INTERVIEW
- Course SchedulePlaud · ONSITE INTERVIEW
- Course Schedule Cycle DetectionGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
- Filter Undesired Comments and Their DescendantsReddit · PHONE SCREEN · ONSITE INTERVIEWReddit interview questions
- Validate and Resolve Evaluation ChainsPlaid · PHONE SCREEN · ONSITE INTERVIEWPlaid interview questions
- Delete and Compact a Forest SubtreePinterest · PHONE SCREEN · ONSITE INTERVIEWPinterest interview questions
- Audit Discounted Category AncestorsFaire · ONSITE INTERVIEW
- Evaluate DivisionPhonePe · ONSITE INTERVIEWPhonePe interview questions
Bloomberg LP interview experiences
- Bloomberg AI-Assisted Coding Round, All Levels: 14 Experiences
- Bloomberg SWE Intern Interview Questions: 68 Questions
- Bloomberg Interview Questions, Level Not Reported: 65 Questions
- Bloomberg Experienced Design & More: 126 Questions (Part 2 of 2)
- Bloomberg Experienced SWE Interviews: 167 Questions (Part 1 of 2)
- Bloomberg New Grad Coding Questions: 121 Questions (Part 2 of 2)