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.
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.