Close
Topic list
Maximum Width In Binary Tree
MEDIUM
38 mins
Other topics
Problem solved
Skill meter
Strings
-
-
Matrices (2D Arrays)
-
-
-
-
Sorting
-
-
Binary Search
-
-
Stacks & Queues
-
-
Trees
-
-
Graph
-
-
Dynamic Programming
-
-
Greedy
-
-
Tries
-
-
Arrays
-
-
SQL
-
-
Binary Search Trees
-
-
Heap
-
-
Bit Manipulation
-
-
Solve problems & track your progress
Checkout your overall progress in every topic here
Become
Sensei
in DSA topics
Open the topic and solve more problems associated with it to improve your skills
Check out the skill meter for every topic
See how many problems you are left with to solve for cracking any stage. Score more than zero to get your progress counted.

# Maximum Width In Binary Tree

Contributed by
Mutiur Rehman khan
Medium
0/80
Avg time to solve 38 mins
Success Rate 50 %
Share

## Problem Statement

#### The width of one level is defined as the length between the leftmost and the rightmost, non-null nodes in the level, where the null nodes in between the leftmost and rightmost are excluded into length calculation.

##### For example :
``````For the given binary tree
``````

``````The maximum width will be at the third level with the length of 3, i.e. {4, 5, 6}.
``````
Detailed explanation ( Input/output format, Notes, Constraints, Images )
##### Sample Input 1 :
``````1 2 3 4 -1 5 6 -1 7 -1 -1 -1 -1 -1 -1
``````
##### Sample Output 1 :
``````3
``````
##### Explanation of Sample Input 1 :
``````The maximum width will be at the third level with the length of 3, i.e. {4, 5, 6}.
``````
##### Sample Input 2 :
``````2 7 5 2 6 -1 9 -1 -1 5 11 4 -1 -1 -1 -1 -1 -1 -1
``````
##### Sample Output 2 :
``````3
``````
##### Explanation of Sample Input 2 :
``````The maximum width will be at the third level i.e. {2, 6, 9} and the fourth level with the length of 3, i.e. {5, 11, 4}. So the maximum width will be 3.
``````
Auto
Console