Hi Everyone,

Can anyone help me out?

My solution for PERMUT2 is exceeding the time limit, and I am having a tough time figuring out why.

Here’s my code:

Hi Everyone,

Can anyone help me out?

My solution for PERMUT2 is exceeding the time limit, and I am having a tough time figuring out why.

Here’s my code:

Thats because you are using a nested loop of-

```
for i in range(n):
for j in range(n):
if i+1 == int(splitlist[j]):
newlist.append(str(j+1))
```

N can be of range 10^5 , so it will easily give you TLE. It is possible to solve this Q without nested loops (i.e. a single loop). You just have to check as (arr[arr[i]]==i) is true for every element in array (in 1 based indexing.). If true, then its ambiguous, else its not.

Here is my code for reference - https://www.codechef.com/viewsolution/14275063