Input: K = 4
5 --------- 1st level width = 1 => (5)
/ \
6 2 -------- 2nd level width = 2 => (6, 2)
/ \ \
7 3 8 -------3rd level width = 4 => (7, 3, NULL, 8)
/ \
5 4 -----------4th level width = 4 => (5, NULL, NULL, 4)
Output: 3
Explanation:
For the given tree, the levels having width K( = 4) are 3 and 4.
Since 3 is the minimum of the two, print the minimum.
Input: K = 7
1 --------- 1st level width = 1 => (1)
/ \
2 9 -------- 2nd level width = 2 => (2, 9)
/ \
7 8 ---------3rd level width = 4 => (7, NULL, NULL, 8)
/ /
5 9 -----------4th level width = 7 => (5, NULL, NULL,
/ NULL, NULL, NULL, 9)
2 -----------5th level width = 1 => (2)
/
1 -----------6th level width = 1 => (1)
Output: 4
Explanation:
For the given tree, the level having width K( = 7) is 4.