C#
Code
# Code
```csharp []
public class Solution {
    public int MinPatches(int[] nums, int n) {
         long max = 0, numsAdded = 0;
 foreach (var num in nums)
 {
     while (num > max + 1)    // O(LogT)
     {
         max += max + 1;     // add no which is 1 greater than last max number we can create till now
         numsAdded++;    // increament count as we just added a new number
         if (n < max)
             return (int)numsAdded;
     }
     max += num;             // add num present in array to max to get next point till where we can create numbe
     if (n < max) break;
 }
 while (n > max)     // O(LogT)
 {
     max += max + 1;
     numsAdded++;
 }
 return (int)numsAdded;
    }
}
```
['C#']