Complete a Flagged Value Range
Learn this problemProblem statement
Each item has an integer value plus a start flag and an end flag. Exactly one item has its start flag set, and exactly one item has its end flag set. The flagged start value is no greater than the flagged end value.
A range is complete when the input contains every integer from the start value through the end value, inclusive. Items may arrive in any order. Duplicate values and values outside the flagged range do not affect completeness.
Return the complete range in ascending order. If at least one required value is absent, return an empty array. For a one-value range, the same item may carry both flags.
Function
completeFlaggedRange(values: int[], startFlags: boolean[], endFlags: boolean[]) → int[]Examples
Example 1
values = [0,1,3,2,7]startFlags = [false,true,false,false,false]endFlags = [false,false,true,false,false]return = [1,2,3]The flags define the inclusive range from 1 through 3. Although 2 appears after the end-flagged item, all three required values are present, so the result is [1,2,3].
Example 2
values = [4,8,6,10]startFlags = [true,false,false,false]endFlags = [false,true,false,false]return = []The flagged range is 4 through 8, but values 5 and 7 are missing. Values outside the range cannot make it complete.
Constraints
1 <= values.length <= 2 * 10^5startFlags.length == values.lengthendFlags.length == values.length-10^9 <= values[i] <= 10^9- Exactly one entry in
startFlagsistrue, and exactly one entry inendFlagsistrue. - The flagged start value is no greater than the flagged end value.
- The inclusive flagged range contains at most
2 * 10^5integers.