Here is the solution:
function minPatches(nums, n)
patches := 0
miss := 1
i := 0
while miss <= n
if i < length(nums) and nums[i] <= miss then
miss := miss + nums[i]
i := i + 1
else
miss := miss + miss
patches := patches + 1
return patches
Time: where is array length. Space: .
Either use an existing number to extend range, or patch with to double the range. Doubling means patches at most.