FastPrepAverage Values by Binary-Tree Level
Problems/Average Values by Binary-Tree Level

Average Values by Binary-Tree Level

Motive logoMotive● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A firsthand Motive report for a full-time phone screen links the Average of Levels in Binary Tree problem. Here the level averages come back as a numeric array.

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

Given the root of a non-empty binary tree, return an array whose value at index d is the arithmetic mean of all node values at depth d.

The root is at depth zero. Return averages from the root level down to the deepest level.

Function

averageOfLevels(root: TreeNode) → List<Double>

Examples

Example 1

root = [3,9,20,null,null,15,7]return = [3.0,14.5,11.0]
root
3920157

The three levels are [3], [9,20], and [15,7].

Example 2

root = [5]return = [5.0]
root
5

A one-node tree has one level.

Constraints

  • The tree contains 1 through 100000 nodes.
  • -1000000000 <= node.val <= 1000000000.
  • Answers within 1e-5 of the exact average are accepted.

More Motive Phone Screen questions

  • Group AnagramsPHONE SCREEN · ONSITE INTERVIEW · Seen Jan 2026
  • Longest Equal-Zero-One SubarrayPHONE SCREEN · ONSITE INTERVIEW · Seen Jan 2026
  • Valid Parenthesis StringPHONE SCREEN · ONSITE INTERVIEW · Seen Jan 2026
  • Search in Rotated Sorted ArrayPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2025
  • Pair Left and Right Shoes by SizePHONE SCREEN · Seen Jun 2025
  • Lowest Common Ancestor in a Binary TreePHONE SCREEN · Seen Apr 2025
  • Mark a Queen’s Attack BoardPHONE SCREEN · Seen Feb 2025
  • Count Product-Divisible PairsPHONE SCREEN · Seen Sep 2024
  • Resolve Variable Equations with Dependency ErrorsPHONE SCREEN · Seen Jun 2024
  • Chunked Round-Robin Row TraversalPHONE SCREEN · Seen May 2024

Similar questions at other companies

  • Maximum-Scoring Consecutive Tree LevelsJane Street · PHONE SCREENJane Street interview questions
  • Minimum Edits to a Perfect Binary TreeSnowflake · PHONE SCREENSnowflake interview questions
  • Find All Paths for a Name in a File SystemThe Walt Disney Company · PHONE SCREENThe Walt Disney Company interview questions
  • Binary Tree Spiral Level OrderAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • Check a Complete Binary TreeGoldman Sachs · PHONE SCREENGoldman Sachs interview questions
  • Binary Tree Right Side ViewGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
  • Same Binary TreeOdoo · PHONE SCREENOdoo interview questions
  • Binary Tree Zigzag Level Order TraversalLinkedIn · PHONE SCREEN · ONSITE INTERVIEWLinkedIn interview questions
  • Insert an Employee into an Organization HierarchyWaymo · PHONE SCREENWaymo interview questions
  • Bottom View of a Binary TreeOracle · PHONE SCREEN · ONSITE INTERVIEWOracle interview questions
All Motive interview questionsSee Motive 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<Double> averageOfLevels(TreeNode root) {
        // write your code here
    }
}
Checking account…