Number of Ways to Reorder Array to Get Same BST
HardLeetCodeCombinatorics & Modular Arithmetic
Approach hintTry it first, then revealHide
The root must stay first; the left and right subtree sequences can then be interleaved in C(L + R, L) ways. Recurse on both sides, multiply, and subtract 1 for the original order.