function check(sequence,l,r){ if(l>=r) return true let root = sequence[r] let j = r-1 while(j>=0&&sequence[j]>root) j-- for(let i=l;i<=j;i++){ if(sequence[i]>root) return false } return check(sequence,l,j)&&check(sequence,j+1,r-1) } ...