FastPrepMaximum Value at Each Tree Level
Problems/Maximum Value at Each Tree Level

Maximum Value at Each Tree Level

Meta logoMeta● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Meta onsite interview. The report asks for the biggest value on each tree level using BFS. We chose that the tree is binary, what an empty tree gives, and the limits. Our version is about 90% the same as the reported question.

Given the root of a binary tree, return the maximum node value at every level, ordered from the root level downward.

Nodes are on the same level when they have the same number of edges from the root. Return exactly one maximum for each existing level, including repeated maximum values. For an empty tree, return an empty array.

The input uses level-order tree notation with null for a missing child. The function receives the constructed TreeNode root.

Function

largestValues(root: TreeNode) → List<Integer>

Examples

Example 1

root = [1,3,2,5,3,null,9]return = [1,3,9]
root
135329

The maximum values at depths zero, one and two are 1, 3 and 9.

Example 2

root = [1,2,3]return = [1,3]
root
123

The root level contributes 1, and the child level contributes 3.

Example 3

root = []return = []
root
empty

An empty tree has no levels, so the result is empty.

Constraints

  • The tree contains between 0 and 10^3 nodes.
  • Node values are signed 32-bit integers and may repeat or be negative.
  • The input is a valid binary tree.

More Meta Onsite Interview questions

  • Multi-Head Attention Forward PassPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Run-Length Encoded Vector Dot ProductPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Mutual-Friend RecommendationsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Deterministic K-Means AssignmentsPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Linear Layer Forward and Backward PassesONSITE INTERVIEW · Seen Sep 2026
  • Reservoir Sampling with Recorded DrawsONSITE INTERVIEW · Seen Sep 2026
  • Stochastic Gradient Descent with MomentumONSITE INTERVIEW · Seen Sep 2026
  • Top K Largest Values with a HeapONSITE INTERVIEW · Seen Sep 2026
  • Partition a Card Deck into FifteensONSITE INTERVIEW · Seen Sep 2026
  • Insert into a Sorted Circular ListONSITE INTERVIEW · Seen Aug 2026

Similar questions at other companies

  • Diagonal Traversal of a Binary TreeAmazon · ONSITE INTERVIEW
  • Delete Nodes and Return Forest RootsGoogle · ONSITE INTERVIEWGoogle interview questions
  • Diameter of an Acyclic Undirected GraphSalesforce · ONSITE INTERVIEWSalesforce interview questions
  • Binary Tree Spiral Level OrderBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • Binary Tree Zigzag TraversalExpedia · ONSITE INTERVIEWExpedia interview questions
  • Top View of a Binary TreeInMobi · ONSITE INTERVIEWInMobi interview questions
  • Diameter of Binary TreeeBay · ONSITE INTERVIEWeBay interview questions
  • Maximum Depth of Binary TreeLinkedIn · PHONE SCREEN · ONSITE INTERVIEWLinkedIn interview questions
  • Symmetric Binary TreeFigma · ONSITE INTERVIEWFigma interview questions
  • Mirror a Binary TreeAMD · ONSITE INTERVIEWAMD interview questions

Meta interview experiences

  • Meta PhD SWE Intern AI Coding Phone Screen: 1 Experience
  • Meta Business Support Engineer Phone Screen: 1 Experience
  • Meta Software Engineer Onsite Questions: 3 Experiences
  • Meta AI Native Engineer OA and Onsite: 1 Experience
  • Meta AI-Native Coding Interview: 3 Experiences
  • Meta Production Engineer Intern Questions: 6 Experiences
All Meta interview questionsSee Meta 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 List<Integer> largestValues(TreeNode root) {
        // Write your solution here.
    }
}
Checking account…