Concise Java Solution Faster than 100% with in depth explanation
Explaination:\nInput: [1, 5, 10]\n\nInitially, our reach is 0. Let\'s start the process of adding elts step by step:\n1) Adding 1st elt, doesn\'t make us miss e
Explaination:\nInput: [1, 5, 10]\n\nInitially, our **reach is 0**. Let\'s start the process of adding elts step by step:\n1) Adding 1st elt, doesn\'t make us miss elts. Since, reach is 0 and 1st element is 1. So Now **reach=1**.\n2) Now, adding 2nd elt(i.e. 5) makes us miss elts 2,3,4 since reach is only 1 till now. So we add the lowest unreachable elt yet i.e. 2. So, now **reach=reach+(reach+1) i.e. 1 +2 = 3**.\n**Why?**\nSince, reach at any stage means that all elts from 1 to reach are reachable for example if reach is 5, all elements i.e 1, 2, 3, 4, 5 are reachable now suppose if we add 6 to it, then we get 6 more elements which can be reached i.e. [1+6, 2+6, 3+6, 4+6, 5+6]. Hence, reach increases by the element we add.\nSo, in above case previous reach was 1, we added (reach+1) element **hence, reach=reach+(reach+1) i.e. reach = 2 * reach + 1.**\n3) Again 2nd element(i.e. 5) cannot be added since reach is still 3, hence 4 is missing. So we add 4 to the array which makes **reach=reach+4 = 3 + 4 = 7.**\n4) Now, we can add 2nd element because it\'s less than reach, hence we don\'t miss any element. \n**Now, reach = reach + 5 = 7 + 5 = 12.**\n5) Next, we add the 3rd element(i.e. 10) since it\'s less than reach and that means we don\'t miss any element.\n**Now, reach = reach + 10 = 12 + 10 = 22**.\nWhich is greater than n, hence we added 2 and 4 to the array as in step 2 and 3.\n\n**Key Points:**\n**1) From 2nd Point:\n\tif(arr[i]>(reach+1)){\n\t\t// This indicates certain elts are missing and we add lowest elt after reach i.e. (reach+1)\n\t\t// 2nd and 3rd Points indicate this.\n\t\treach=reach+(reach+1)\n\t\telts_added+=1;\n\t}else{\n\t\t// This indicates that no elts are missing - 4th and 5th Points indicates this.\n\t\treach=reach+(arr[i]);\n\t}**\n\t\n\tNow below code should make sense.\n\t`\n\tpublic int minPatches(int[] nums, int n) {\n        int ans=0,i=0;\n        long reach=0;\n        while(reach<n){\n            if(i<nums.length && nums[i]<=(reach+1))\n                reach+=nums[i++];\n            else{\n                reach=(reach<<1)+1;\n                ans++;\n            }\n        }\n        return ans;\n    }\n\t`
[]