You are given a neighborhood represented as a 2D array blocks, where each blocks[i] is an array of integers representing the house colors in the i-th block.
For each block, remove duplicate house colors and sort the remaining colors in ascending order. Return the resulting neighborhood, where each block contains only uniquely colored houses in sorted order.
Function Signature
def shuffle_neighborhood(blocks: list[list[int]]) -> list[list[int]]:
Rules
-
Duplicates are removed within a block only. The same color can appear in several blocks of the output.
-
The output has one list per input block, in the same order as the input.
-
Each output list contains every distinct color of its block exactly once, in strictly increasing order.
Constraints
-
1 <= blocks.length <= 100
-
1 <= blocks[i].length <= 100
-
1 <= blocks[i][j] <= 1000
Examples
Input: blocks = [[3,1,2,3,1],[5,5,4,3],[7,8,7,9,8]]
Output: [[1,2,3],[3,4,5],[7,8,9]]
Block 0 holds the colors 1, 2 and 3 with repeats, so it becomes [1,2,3]. Block 1 reduces to {3,4,5} and block 2 to {7,8,9}, each written in ascending order.
Input: blocks = [[1],[2,2,2],[3,1,2]]
Output: [[1],[2],[1,2,3]]
The single house in block 0 stays as it is, the three houses of color 2 in block 1 collapse to one, and block 2 has no repeats but still has to be sorted.