This question evaluates a candidate's ability to perform duplicate detection and compression of sequences of fixed-length tuples, exercising skills in data structures, mapping/hash concepts, array manipulation, and preserving first-seen ordering.
You are given an array of vertices (a 2D array). Each vertex may repeat. Implement a simple “compression” that produces:
unique_vertices
: the list of unique vertices,
preserving the order of first appearance
.
indices
: for each vertex in the original array, the index of its corresponding vertex in
unique_vertices
.
vertices
: a list of
n
vertices
unique_vertices
: list of unique vertices in first-seen order
indices
: integer list of length
n
Input:
[[2,2,2], [0,1,0], [2,1,2], [0,1,0]]
Output:
unique_vertices = [[2,2,2], [0,1,0], [2,1,2]]
indices = [0, 1, 2, 1]