Solution found codemonk -cyclic shift [need help]

Hello everyone I found the solution for the problem on the youtube channel of HackerEarth. but the solution is in python. and I have no idea about python.
can someone translate the solution into C++; (because I am not able to identify the time complexity of the python code and also have difficulty in understanding the logic)
it would be very helpful,
I am stuck on this problem for four months finally got the solution, Please Help



The question has weak testcases which allows O(n^2) solutions to pass.

1 Like