Given a permutation, compute the unique MEX across all subarrays. Then, reverse the problem, given a binary string where a $$$1$$$ at index $$$i$$$ means that a subarray with MEX $$$i$$$ exists (and $$$0$$$ means it doesn't), compute the number of permutations that satisfy these constraints.
I created a video discussing the ideas to solve both the problem in $$$O(N)$$$. Practice Problem








