public int minPatches(int[] nums, int n) {
        int patch = 0;
        long t = 1;
        int i = 0;
        while(t <= n) {
            if (i == nums.length || t < nums[i]) {
                patch++;
                t += t;
            } else {
                t = nums[i] + t;
                i++;
            }
        }
        return patch;
    }
Leetcode variation https://leetcode.com/problems/patching-array/
src/com/interview/array/SmallestIntegerNotRepresentedBySubsetSum.java