Can we solve this in optimal time and space without cyclic sort, in the stated optimal O(n) time and O(n) space? If so, it may help the course to swap in a problem that requires the pattern.
def first_k_missing_numbers(arr, k):
nums = set(arr)
result = []
i = 1
while len(result) < k:
if i not in nums:
result.append(i)
i += 1
return result
Course: Grokking Coding Interview Patterns in Python - Learn Interactively
Lesson: Find the First K Missing Positive Numbers - Grokking Coding Interview Patterns in Python