There is some issue in cycle removal


working fine on tc provided by me

https://ide.codingblocks.com/s/301377 updated still showing TLE for 1 tc

@akshitmehta
Your code uses a lot of nested loops which in turn increase the overall time complexity of your algorithm. In the worst case your code goes up to O(n^2) time complexity. This is bad for larger testcases.
This problem can be solved in O(n) time. Try making some optimisations. Do not use nested loops. That is not needed.

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.