FastPrepValidate a Binary Search Tree
Problems/Validate a Binary Search Tree

Validate a Binary Search Tree

NVIDIA logoNVIDIA● MediumNEW GRADPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: An NVIDIA phone-screen interview report for a deep-learning role, posted on behalf of the candidate, names BST validation as its second coding exercise. It leaves out the policy for duplicate keys, what happens for an empty tree, the node format, and the limits. Here we use strict BST ordering and an ordinary binary-tree interface.

Our version is about 70% the same as the reported question.

Given the root of a binary tree, return whether it is a valid binary search tree.

For this practice, every node in a left subtree must have a value strictly less than its ancestor, and every node in a right subtree must have a value strictly greater than its ancestor. This rule applies to every ancestor, not only to each node’s immediate children. Duplicate values make the tree invalid. An empty tree is valid.

Input examples use level-order array notation with null for missing children.

Function

isValidBST(root: TreeNode) → boolean

Examples

Example 1

root = [2,1,3]return = true
root
213

The left value is smaller than 2 and the right value is greater.

Example 2

root = [5,1,4,null,null,3,6]return = false
root
51436

Value 3 lies in the root’s right subtree but is less than 5.

Example 3

root = [2,2,3]return = false
root
223

A duplicate value in the left child violates strict BST ordering.

Constraints

  • The tree contains 0 to 100 nodes.
  • -10^9 <= node.val <= 10^9.
  • Use strict inequalities for every subtree bound.

More NVIDIA Phone Screen questions

  • Network Layer Execution OrderPHONE SCREEN · Seen Nov 2026
  • Paged KV Cache AccessPHONE SCREEN · Seen Nov 2026
  • Sliding Window Attention over a KV CachePHONE SCREEN · Seen Nov 2026
  • Summarize Server Healthcheck LogsPHONE SCREEN · Seen Oct 2026
  • Hash Partition OffsetsPHONE SCREEN · Seen Oct 2026
  • Filter Paginated Medical RecordsPHONE SCREEN · Seen Oct 2026
  • Least Frequently Used CachePHONE SCREEN · Seen Oct 2026
  • Parallel String Counts with a Custom Hash TablePHONE SCREEN · Seen Oct 2026
  • Simulate a Reference-Counted Smart PointerPHONE SCREEN · Seen Aug 2026
  • Streaming Top-K Frequent ElementsPHONE SCREEN · Seen Aug 2026

Similar questions at other companies

  • Lowest Common Ancestor in a BST and a Binary TreeGreyOrange · PHONE SCREENGreyOrange interview questions
  • N-ary Index-Path Encoder and DecoderBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • House Robber IIIOkta · PHONE SCREENOkta interview questions
  • Render a Task Tree from CSV RowsStripe · PHONE SCREEN · ONSITE INTERVIEWStripe interview questions
  • Validate Binary Search TreeKotak Mahindra Bank · PHONE SCREENKotak Mahindra Bank interview questions
  • House Robber IIIGoldman Sachs · PHONE SCREENGoldman Sachs interview questions
  • Binary Tree Target-Sum PathsByteDance · PHONE SCREENByteDance interview questions
  • House Robber IIIVisa · PHONE SCREENVisa interview questions
  • Find All Paths for a Name in a File SystemThe Walt Disney Company · PHONE SCREENThe Walt Disney Company interview questions
  • Validate a BST with a Custom ComparisonApple · PHONE SCREENApple interview questions

NVIDIA interview experiences

  • NVIDIA Full-Time SWE Onsite Scheduling: 1 Experience
  • NVIDIA OA: What It Tests (2026)
  • NVIDIA DevOps, QA and Infra Intern Interviews: 12 Experiences
  • NVIDIA Ignite Internship OA Experience
  • NVIDIA Software Intern Interview Questions: 9 Experiences
  • NVIDIA Ignite SWE Intern OA Questions: 6 Experiences
All NVIDIA interview questionsSee NVIDIA hiring insights
Saved
/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode() {}
 *     TreeNode(int val) { this.val = val; }
 *     TreeNode(int val, TreeNode left, TreeNode right) {
 *         this.val = val;
 *         this.left = left;
 *         this.right = right;
 *     }
 * }
 */
class Solution {
    public boolean isValidBST(TreeNode root) {
        // Write your code here.
    }
}
Checking account…