educative.io

Why is Time complexity O(N+N)

Why is the Time Complexity is O(N+N)? we have while loop inside a for loop and number of time while loop execute can be vary right?

True! They do very small test cases and think their while loops act like O(1) operations. Fully wrong complexities in all problems. Its better for everyone to skip complexity sections because they give wrong examples and calculations

Yes the number of times while loop executes can vary but this number will never exceed N and the while loop processes each number only once irrespective of the outer loop. Hence, the time complexity mentioned in the lesson is correct.

1 Like