Next Permutation

I am getting TLE error, How is it possible to solve this question In less than O(n^2) time complexity?
MY code: https://ide.codingblocks.com/s/281283

hello @amarshmalik0
u can use next_permuation stl function.

or
here is the algorithm

Please first take a look at my code first, I have used next_permutation only. I’m still getting TLE error.

u r not decrementing t.inside while loop

1 Like

Oh I got it, sorry that was a really silly mistalke.