Getting Time limit exceeded

Hello…
I am doing this question from hackerearth…

In this question … first i have generated all the binary digit for number of x…
Now after this… I have placed each representation on place of x and calculated the maximum size of subarray having same number of 1’s and 0’s.

This is my submission…
https://www.hackerearth.com/submission/52035587/

Please look at this…

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.