Fill Missing Values in a Fixed-Step Sequence
Problem statement
Insert missing integers into values so that every consecutive output gap equals step.
Keep all given values. Return the complete sequence in increasing order, beginning at the first given value and ending at the last. Do not add values outside this range. The input is already sorted, and all existing gaps are positive multiples of step. A single given value is returned unchanged.
Function
fillMissingValues(values: int[], step: int) → int[]Examples
Example 1
values = [5,10,20]step = 5return = [5,10,15,20]The gap from 10 to 20 is two steps of 5, so insert 15. The other gap already has the required size.
Example 2
values = [5,25,35]step = 10return = [5,15,25,35]Insert 15 between 5 and 25. Each consecutive output gap is then 10.
Example 3
values = [-3]step = 4return = [-3]A single given value has no gap to fill, so return [-3].
Constraints
1 <= values.length <= 200-1000000 <= values[i] <= 10000001 <= step <= 1000000- The values are strictly increasing, and each consecutive gap is a positive multiple of
step. (values[values.length - 1] - values[0]) / step <= 1000