param { number } sequence return { boolean } function verifySquenceOfBTS ( sequence ) { if ( ! sequence ) { return false ; } let len = sequence . length ; let root = sequence [ len - 1 ] ; let l = 0 ; for ( ; l < len - 1 ; l ++ ) { if ( sequence [ l ] > root ) { break ; } } let r = l ; for ( ; r < len - 1 ; r ++ ) { if ( sequence [ r ] < root ) { return false ; } } let left = true , right = true ; if ( l > 0 ) { left = verifySquenceOfBTS ( sequence . slice ( 0 , l ) ) ; } if ( l < len - 1 ) { right = verifySquenceOfBTS ( sequence . slice ( l , len - 1 ) ) ; } return ( left && right ) ; } export { verifySquenceOfBTS } ;