package leetcode;

/**
 * https://leetcode.com/problems/kth-missing-positive-number/
 */
public class Problem1539 {
    public int findKthPositive(int[] arr, int k) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem1539 prob = new Problem1539();
        System.out.println(prob.findKthPositive(new int[]{2,3,4,7,11}, 5)); // 9
        System.out.println(prob.findKthPositive(new int[]{1,2,3,4}, 2)); // 6
    }
}

package leetcode;

/**
 * https://leetcode.com/problems/kth-missing-positive-number/
 */
public class Problem1539 {
    public int findKthPositive(int[] arr, int k) {
        int count = 0;
        int i = 1;
        int j = 0;
        while (true) {
            if (j < arr.length && arr[j] == i) {
                j++;
            } else {
                count++;
                if (count == k) {
                    return i;
                }
            }
            i++;
        }
    }
}

Solve problem 1539