TLE in query bits

sample input is showing correct, but all test cases are showing TLE,please help.

@Gurankit_Pal_Singh your logic is not efficient try this logic:

thank you sir for resolving my doubt

@Gurankit_Pal_Singh no problem bro