Your question is 2D Array Compression With Indices. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Applied Intuition simulation assets may store repeated 2D vertices. Implement a compression function that keeps one copy of each distinct vertex and replaces every original vertex with the index of its retained copy.
Preserve the order in which unique vertices first appear. Two vertices are equal when their coordinate lists contain the same values in the same order.
Given vertices, a list of n coordinate lists, return a two-element list:
unique_vertices: the distinct coordinate lists in first-occurrence order.indices: a list of length n, where indices[i] is the index of vertices[i] in unique_vertices.Each coordinate list has the same positive dimension, and coordinates are integers. Do not mutate the input.
def compress_vertices(vertices):