LC: 163. Missing Ranges - spiralgo/algorithms GitHub Wiki
163. Missing Ranges:
The Essence: This quote from the LeetCode has the essence, indeed:
Since the input array, nums, is sorted ascendingly and all the elements in it are within the given [lower, upper] bounds, we can simply check consecutive elements to see if they differ by one or not. If they don't, then we have found a missing range.
When nums[i] - nums[i-1] == 1, we know that there are no missing elements between nums[i-1] and nums[i]. When nums[i] - nums[i-1] > 1, we know that the range of elements, [nums[i-1] + 1, nums[i] - 1], is missing.
Details:
The problem-solver can find the detailed implementation here: https://github.com/spiralgo/algorithms/blob/master/src/main/java/algorithms/curated170/easy/MissingRanges.java