Level array store the number of nodes on level i initially all values are zero
let level = Array . from ( { length : maxElement + 1 } , ( _ , i ) => 0 ) ; for ( let i = 0 ; i < N ; i ++ ) { level [ arr [ i ] ] ++ ; }