Find the First K Missing Positive Numbers

Try to solve the Find the First K Missing Positive Numbers problem.

Statement

Given an unsorted integer array, arr, of size nn and a number kk, your task is to find the first kk missing positive numbers from the array. If there are less than kk missing positive numbers in the array, then add the remaining missing numbers by adding the values after the last value of the array until we have kk missing positive numbers. Ignore all negative numbers.

Constraints:

  • n=n = arr.length

  • 1≤k≤1041 \leq k \leq 10^4

  • −104≤-10^4 \leq arr[i] ≤104\leq 10^4

  • 0≤n≤1040 \leq n \leq 10^4

Examples

Create a free account to view this lesson.

Continue your learning journey with a 14-day free trial.

By signing up, you agree to Educative's Terms of Service and Privacy Policy