LeetCode
Valid Permutations for DI Sequence
Click
here
for an explanation.