Unlock Hashing Section

I have tried to solve this problem but my approach is getting TLE in one test case. Here is my code : https://ide.codingblocks.com/s/239378 . How Can i improve this?

hi @gourav this is my approach https://ide.codingblocks.com/s/240359 i have used the logic provided in the hint video.