Validate BST Node Descriptions
Updated
Problem statement
You are given an array nodes. Each row [value, left, right] describes one proposed binary-tree node:
valueis the node's unique integer value.leftis the value of its left child, or-1when it has no left child.rightis the value of its right child, or-1when it has no right child.
Determine whether all rows together describe exactly one valid binary search tree. A valid description must have exactly one root, every non-root node must have exactly one parent, every referenced child must have its own row, every node must be reachable from the root, and the strict binary-search-tree ordering rule must hold for every descendant.
Return the root value when the description is valid. Otherwise, return -1.
Function
findValidBstRoot(nodes: int[][]) → intExamples
Example 1
nodes = [[17,-1,-1],[15,13,17],[7,-1,-1],[13,-1,-1],[5,3,7],[3,-1,-1],[10,5,15]]return = 10The rows form one connected tree rooted at 10. Every value in its left subtree is smaller, and every value in its right subtree is larger.
Example 2
nodes = [[2,3,-1],[3,-1,-1]]return = -1Node 3 is described as the left child of 2, which violates the strict binary-search-tree ordering rule.
Constraints
1 <= nodes.length <= 10^5.nodes[i].length == 3.0 <= value <= 10^9, and allvalueentries are distinct.- Each child entry is
-1or an integer from0through10^9.
More Airbnb Online Assessment questions
- Count Card Duel RoundsOA · Seen Nov 2026
- Count Lamps Lighting Each PointOA · Seen Nov 2026
- Simulate Orchard Rot SpreadOA · Seen Nov 2026
- Sort Adjacent PairsOA · Seen Nov 2026
- In-Memory File SystemOA · Seen Nov 2026
- Task Management SystemOA · Seen Nov 2026
- Recipe Management SystemOA · Seen Nov 2026
- Progressive Banking SystemOA · Seen Nov 2026
- Credit Accounts with Scheduled TransfersOA · Seen Oct 2026
- Parcel Attribute Store with TTLOA · Seen Oct 2026
Similar questions at other companies
- Render a Comment HierarchyAmazon · ONSITE INTERVIEW
- Render a Stable Comment HierarchyBobyard · PHONE SCREEN
- Palindromic Paths to the RootRippling · OARippling interview questions
- Merge Row Trees by Key PathHudson River Trading · OAHudson River Trading interview questions
- Chain of CommandIMC Trading · OAIMC Trading interview questions
- Chain of CommandUber · OAUber interview questions
- Build and Render an Organization Role TreeStripe · OAStripe interview questions
- Get Most Hydrated TeamAirtable · OAAirtable interview questions
- Recursive Display SortFigma · PHONE SCREEN · ONSITE INTERVIEWFigma interview questions
- Count Distinct Rooted-Tree GraftsThe D.E. Shaw Group · PHONE SCREENThe D.E. Shaw Group interview questions
Airbnb interview experiences
- Airbnb OA · November 2026
- Airbnb Campus and Full-Time SWE OA / Interviews: 9 Experiences
- Airbnb Intern Phone Interviews: 21 Experiences (Part 7 of 7)
- Airbnb Intern OA and Phone Screens: 17 Experiences (Part 6 of 7)
- Airbnb Intern OA and Onsite Rounds: 16 Experiences (Part 5 of 7)
- Airbnb Intern OA, Diplomacy Game: 19 Experiences (Part 4 of 7)