FastPrepClosest Binary Search Tree Value — Base Practice
Problems/Closest Binary Search Tree Value — Base Practice

Closest Binary Search Tree Value — Base Practice

Roblox logoRoblox● EasyFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Our version is about 25% the same as the reported question. The original report, written by its author, says a Roblox technical screen asked a harder variant of Closest Binary Search Tree Value. The author says clearly that they no longer remember the extra constraints. So the exact variant cannot be rebuilt from the report. This page shows only the standard base exercise. It does not claim that its tie rule, array interface, signature, examples, constraints, or edge cases were part of the interview.

You are given a binary search tree and a target value. Return the value in the tree whose absolute difference from target is smallest. If two values are equally close, return the smaller value.

For this executable base exercise, the tree is supplied as a fully populated level-order array root: the children of index i are at 2 * i + 1 and 2 * i + 2 when those indices exist.

Use the binary-search-tree ordering to walk toward the target while tracking the best value seen.

Function

closestValue(root: int[], target: float) → int

Examples

Example 1

root = [4, 2, 5, 1, 3]target = 3.714286return = 4

|4 - 3.714286| = 0.286 is smaller than |3 - 3.714286| = 0.714, so 4 is closest.

Example 2

root = [1]target = 4.428571return = 1

The tree has a single node, so 1 is the only and therefore closest value.

Example 3

root = [2, 1, 3]target = 2.5return = 2

Both 2 and 3 are 0.5 away from 2.5. Return the smaller value, 2.

Constraints

  • 1 <= number of nodes <= 10^4
  • 0 <= Node.val <= 10^9
  • -10^9 <= target <= 10^9
  • The input array is a level-order serialization of a valid binary search tree.

More Roblox Phone Screen questions

  • Most Frequent Call Path From Function Trace LogsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Design Search Autocomplete SystemPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Candy Crush Grid Matching and GravityPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Implement a Rate LimiterPHONE SCREEN · Seen Oct 2026
  • Rate Limit by Multiple Request FieldsPHONE SCREEN · Seen Oct 2026
  • Topological Sort with Secondary OrderingPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Time-Aware Search AutocompletePHONE SCREEN · Seen Oct 2026
  • Most Frequent Call Stack Per ThreadPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Rate Limiter Sliding Window With Per-Entity LimitsPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Grid Pathfinding with Obstacles (DFS)PHONE SCREEN · ONSITE INTERVIEW · Seen Jun 2026

Similar questions at other companies

  • Merge Two Binary TreesSnowflake · PHONE SCREENSnowflake interview questions
  • Sum All Values in a Binary TreeDuolingo · PHONE SCREENDuolingo interview questions
  • Sum Root-to-Leaf Binary NumbersOracle · PHONE SCREENOracle interview questions
  • Symmetric Binary TreeDocuSign · PHONE SCREENDocuSign interview questions
  • Lowest Common Ancestor in an Inserted BSTAmazon · PHONE SCREEN
  • Count One-Valued Regions in a Binary TreeGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
  • Maximum Depth of Binary TreeLinkedIn · PHONE SCREEN · ONSITE INTERVIEWLinkedIn interview questions
  • Maximum Value in a Binary TreeAkuna Capital · PHONE SCREENAkuna Capital interview questions
  • First Common Ancestor with Parent PointersMeta · PHONE SCREENMeta interview questions
  • Binary Tree Level-Order Traversal by LevelsAdobe · PHONE SCREEN · ONSITE INTERVIEWAdobe interview questions

Roblox interview experiences

  • Roblox OA: What It Tests (2026)
  • Roblox New Grad Early OA Tasks: 10 Experiences (Part 7 of 7)
  • Roblox New Grad Engineer Rounds: 13 Experiences (Part 6 of 7)
  • Roblox New Grad HackerRank OA: 18 Experiences (Part 5 of 7)
  • Roblox New Grad CodeSignal Finals: 23 Experiences (Part 4 of 7)
  • Roblox New Grad Games and BQ: 25 Experiences (Part 3 of 7)
All Roblox interview questionsSee Roblox hiring insights
Saved
class Solution {
    public int closestValue(int[] root, float target) {
      // write your code here
    }
}
Checking account…