Unlock Problem of Hashing

question link is https://hack.codingblocks.com/contests/c/537/1559
my code link is https://ide.codingblocks.com/s/43190
i am getting tle in one of the testcases please help

Your code should not give a TLE according to me because this is the best possible solution. I think the time constraints are kept too tight for C++ or there is some problem with the test cases, thats why there is no submission.

https://ide.codingblocks.com/s/43204
This is the best possible way i can solve this problem.

Even though in constraints it is specified q>=1 but in one of the case i think q is negative that’s why tle is coming as on adding a check to ensure q is positive the code gets passed in all the cases.
https://ide.codingblocks.com/s/43208

1 Like

thanks bro , you are right