Ad
  • Default User Avatar

    Hi; the number of lines of code doesn't say anything about the overall time complexity of an algorithm.

    For example, if I write for i in range(10**9971599599): print i, it will also time out even though it is "only 2 lines".

    In your case, your algorithm is O(n^2) complexity; and the big test you are failing has approximately 8,000,000 elements in it - therefore you algorithm is performing approximately 8000000 ** 2 operations which is very large! You need to find a faster approach (i.e. one that doesn't need to perform so many operations).