Bootcamps
Masterclasses
Menu
Courses
Account
Login / Sign Up

Find Largest Value in Each Tree Row

Medium Acceptance 50% Points 30

Given a binary tree, find the largest value in each level.

Examples
Example 1

Example 1

Input: root[] = [1, 2, 3]

Output: [1, 3]

Explanation: First traverse the first level then second level.

Example 2

Example 2

Input: root = [3,9,20,N,N,15,7]

Output: [3, 20, 15]

Explanation: Traverse the tree level wise, first traverse the first level, then second and so on.

Constraints
  • 1 = number of nodes = 10^5
  • 0 = node->data = 10^9
Hints
  • Expected Time Complexity: O(n)
  • Expected Auxiliary Space: O(n).
Topics
Tree
Companies
Amazon Microsoft Google DE Shaw Flipkart
Added 11 Mar 2025 50% acceptance
Ln 1, Col 1Sign in to save your code
1 2 3
1 3