educative.io

Time complexity should be O(n+n) = O(n)

Since the last loop can potentially run for O(n). Good problem tho.

Your are assuming k <= n which is not necessarily true. O(k) is correct.