Can't find the problem in my code. Help!

Question : Ambiguous Permutations Submissions | CodeChef
My Solution : Solution: 50177597 | CodeChef

        for i in new_nums:
            ans[i-1] = new_nums.index(i)+1

My Python is not great, but I believe this is O(n^2), and n can be as high as 10^5.

I am new to programming so I am not familiar with some stuffs. But it passes all the test cases. Shouldn’t the problem arise while running the test cases?

The “problem” is that your algorithm is asymptotically too slow, so will mainly manifest for large testcases only.

Try creating a text file with the following contents:

First line: the number 100000
Second line: all numbers from 1 to 100000, separated by spaces
Third line: the number 0

provide the contents of this text file as input to your solution and see how long it takes for your solution to process it :slight_smile:

1 Like