Count is used to diffentiate each level of the tree
let count = 1 ; let min_v = Number . MAX_VALUE ; while ( qt . length > 0 ) { let temp = qt [ 0 ] ; min_v = Math . min ( min_v , temp . key ) ; qt . shift ( ) ; if ( temp . left != null ) { qt . push ( temp . left ) ; } if ( temp . right != null ) { qt . push ( temp . right ) ; } count -- ; if ( count == 0 ) { levelMin . push ( min_v ) ; min_v = Number . MAX_VALUE ; count = qt . length ; } } }