Card Range Obfuscation Part 4 (ML Eng :)
Problem statement
Part 4 — merge adjacent ranges of the same brand
First apply the Part 1 and Part 2 obfuscation rules to the non-overlapping input intervals: sort by suffix start, extend the first interval to 0000000000, assign each middle gap to the interval on its lower side, and extend the final interval to 9999999999.
Then merge consecutive adjusted intervals when they have the same brand. The merged interval starts at the first interval's start and ends at the last interval's end. Repeat until no adjacent result rows share a brand. Prefix every suffix boundary with the six-digit BIN and return the rows in ascending start order.
Source scope: the available Part 4 source consists of the merge diagram and examples; it does not define how merging interacts with Part 3 nested ranges. This runnable Part 4 contract therefore limits its input to non-overlapping intervals instead of inventing that missing rule.
Function
cardRangeObfuscation4(BIN: int, N: int, info: String[][]) → String[][]Examples
Example 1
BIN = 424242N = 2info = [["0000000000","5999999999","VISA"],["6000000000","9999999999","VISA"]]return = [["4242420000000000", "4242429999999999", "VISA"]]The two VISA intervals are adjacent and together cover the full suffix range, so they merge into one VISA interval.
Example 2
BIN = 424242N = 3info = [["1000000000","3999999999","VISA"],["5000000000","6999999999","VISA"],["8000000000","9999999999","MASTERCARD"]]return = [["4242420000000000", "4242427999999999", "VISA"],["4242428000000000", "4242429999999999", "MASTERCARD"]]Extend the first VISA interval left to 0000000000 and through the gap before the second VISA interval. Extend the second VISA interval through the gap before MASTERCARD. The adjacent VISA results then merge into one interval ending at 7999999999.
Constraints
BINhas exactly six decimal digits andN == info.length > 0.- Each row is
[startSuffix, endSuffix, brand]; both suffixes contain exactly ten decimal digits andstartSuffix <= endSuffix. - Input intervals are non-overlapping. They may be unsorted and may have gaps.
- Fill gaps using the interval on the lower side, then merge consecutive adjusted intervals with equal brands.
- Result rows are inclusive full 16-digit card-number intervals sorted by suffix start.