Find Largest Value in Each Tree Row
Medium Acceptance 50.00% Points 30.00
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.
Hints
Hint 1
Expected Time Complexity: O(n)
Hint 2
Expected Auxiliary Space: O(n).
Constraints
- 1 = number of nodes = 10^5
- 0 = node->data = 10^9
Companies
Amazon Microsoft Google DE Shaw Flipkart
Track your submissions
Please log in to review your progress and explore code submissions from other participants.
Unlock the full solution
Please log in to access detailed answers and explanations.
Join the discussion
Please log in to join conversations with other participants.