Title: #1060 - Missing Element in Sorted Array - LeetCode JavaScript Solutions
Open Graph Title: #1060 - Missing Element in Sorted Array - LeetCode JavaScript Solutions
X Title: #1060 - Missing Element in Sorted Array - LeetCode JavaScript Solutions
Description: Given an integer array nums which is sorted in ascending order and all of its elements are unique and given also an integer k, return the kt...
Open Graph Description: Given an integer array nums which is sorted in ascending order and all of its elements are unique and given also an integer k, return the kt...
X Description: Given an integer array nums which is sorted in ascending order and all of its elements are unique and given also an integer k, return the kt...
Keywords:
Opengraph URL: https://leetcodejavascript.com/solutions/missing-element-in-sorted-array
Domain: leetcodejavascript.com
{"@context":"https://schema.org","@type":"Code","url":"https://leetcodejavascript.com/solutions/missing-element-in-sorted-array","name":"#1060 - Missing Element in Sorted Array - LeetCode JavaScript Solutions","description":"Given an integer array nums which is sorted in ascending order and all of its elements are unique and given also an integer k, return the kt...","programmingLanguage":"JavaScript","codeRepository":"https://github.com/JoshCrozier/leetcode-javascript","codeSampleType":"JavaScript","text":"/**\n * @param {number[]} nums\n * @param {number} k\n * @return {number}\n */\nvar missingElement = function(nums, k) {\n const n = nums.length;\n\n if (k > getMissingCount(n - 1)) {\n return nums[n - 1] + k - getMissingCount(n - 1);\n }\n\n let left = 0;\n let right = n - 1;\n\n while (left < right) {\n const mid = Math.floor((left + right) / 2);\n\n if (getMissingCount(mid) < k) {\n left = mid + 1;\n } else {\n right = mid;\n }\n }\n\n return nums[left - 1] + k - getMissingCount(left - 1);\n\n function getMissingCount(index) {\n return nums[index] - nums[0] - index;\n }\n};","keywords":"LeetCode 1060, #1060 - Missing Element in Sorted Array, Medium, JavaScript solution","learningResourceType":"Code","isAccessibleForFree":true,"educationalLevel":"intermediate","interactivityType":"mixed"}
| author | LeetCodeJavascript.com |
| og:type | article |
| og:image | https://leetcodejavascript.com/og-image.jpg |
| og:site_name | LeetCode JavaScript Solutions |
| twitter:card | summary_large_image |
| twitter:url | https://leetcodejavascript.com/solutions/missing-element-in-sorted-array |
| twitter:image | https://leetcodejavascript.com/og-image.jpg |
| twitter:creator | @joshcrozier |
| theme-color | #1f2937 |
Links:
| LeetCodeJavascript.com | https://leetcodejavascript.com/ |
| Star on GitHub | https://github.com/JoshCrozier/leetcode-javascript |
| Back to all solutions | https://leetcodejavascript.com |
| View on LeetCode | https://leetcode.com/problems/missing-element-in-sorted-array/ |
| View on GitHub | https://github.com/JoshCrozier/leetcode-javascript/blob/master/solutions/1060-missing-element-in-sorted-array.js |
| Array | https://leetcodejavascript.com/tags/array |
| Binary Search | https://leetcodejavascript.com/tags/binary-search |
| Josh Crozier | https://joshcrozier.com |
Viewport: width=device-width, initial-scale=1.0
Robots: index, follow