class Solution { bool check(vector<int>& sequence, int l, int r) { if(l >= r) return true; int root = sequence[r]; int j = r - 1; while(j >= 0 && sequence[j] > root) j--; for(int i = l; i <= j; ++i) // ...