gokulraaj59's blog

By gokulraaj59, history, 20 months ago, In English

my code 169668033

getting TLE in test 2, have used fast_IO and verified this time complexity with solution solution blogalso.. have used same logic

what I am doing wrong here..


def remove(arr, ele): arr.remove(ele) return arr t = int(input()) for _ in range(0, t): n = int(input()) a = [] op = [] for i in range(1, n+1): a.append(i) # print(a) for i in range(0, n-1): # a.sort() x = a[-1] y = a[-2] a.append(round( (x+y)/2) ) op.append([x,y]) a = remove(a, x) a = remove(a, y) sys.stdout.write(str(a[0]) + "\n") for i in op: sys.stdout.write(" ".join(map(str,i)) + "\n")
  • Vote: I like it
  • -1
  • Vote: I do not like it

| Write comment?
»
20 months ago, # |
  Vote: I like it 0 Vote: I do not like it

arr.remove(ele) is O(n) time not O(1) so your overall algorithm is O(n^2)