C++ | BitMasking
\nclass Solution {\npublic:\nint a1=INT_MAX;\nint a2=INT_MIN;\n\nvoid dfs(int i,int j,int mask,int n,int first,int second,int t){\n   \n     if(i>=j){\n        
```\nclass Solution {\npublic:\nint a1=INT_MAX;\nint a2=INT_MIN;\n\nvoid dfs(int i,int j,int mask,int n,int first,int second,int t){\n   \n     if(i>=j){\n         return dfs(1,n,mask,n,first,second,t+1);\n     }\n     \n     while(!(mask&(1<<i))&&i<j)i++;\n     while(!(mask&(1<<j)) &&i<j)j--;\n     if(i==j){\n         return dfs(1,n,mask,n,first,second,t+1);\n     }\n    \n    if((i==first&&j==second) || (i==second && j==first)){\n        \n        a1=min(a1,t);\n        a2=max(a2,t);\n        return ;\n    }\n    if(i==first || i==second){\n        return dfs(i+1,j-1,(mask^(1<<j)),n,first,second,t);\n    }else if(j==second || j==first){\n        return dfs(i+1,j-1,(mask^(1<<i)),n,first,second,t);\n    }else{\n        dfs(i+1,j-1,(mask^(1<<i)),n,first,second,t);\n        dfs(i+1,j-1,(mask^(1<<j)),n,first,second,t);\n    }\n      \n        \n    }\n    \n    \n    vector<int> earliestAndLatest(int n, int first, int second) {\n        \n        int mask = (1<<(n+1))-1;\n        \n        dfs(1,n,mask,n,first,second,1);\n        return {a1,a2};\n        \n        \n    }\n};\n\n\n```
['C']