After drwing the recursion tree of the same problem , i found that [mask][pos] will not be repeated int the tree , like there are distinct [mask][pos] pairs.
Distinct [mask][pos] pairs
if the pairs are less than 1e6 , then it will work in given time.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.