← Questions

Compress a vertex list into unique vertices and indices

0
Applied IntuitionCodingLast asked Feb 2026

A coding interview question asked in Applied Intuition's technical phone screen, last asked Feb 2026. It tests hash map and arrays.

A mesh is stored as a flat list of vertices, each a tuple of coordinates, and many vertices repeat. Compress it into a list of unique vertices, in the order each first appears, plus an index array such that [unique[i] for i in indices] rebuilds the original list exactly.

Interface

Unless you agree on a different interface with the interviewer, assume:

  • compress(vertices: list[tuple[float, ...]]) -> tuple[list[tuple[float, ...]], list[int]] returns (unique, indices). An empty input returns ([], []).
  • decompress(unique, indices) -> list[tuple[float, ...]] rebuilds the original list.

Example

compress([(0,0,0), (1,0,0), (0,1,0), (1,0,0), (0,0,0), (0,1,0)])
  ->  ([(0,0,0), (1,0,0), (0,1,0)], [0, 1, 2, 1, 0, 2])

Constraints

  • All tuples have the same length.
  • Two vertices are the same only when every coordinate is equal.
  • len(indices) == len(vertices) and every index is in range(len(unique)).

Clarifying questions

  • Are coordinates integers or floats? If floats, are 0.0 and -0.0, or values that differ by rounding noise, the same vertex?
  • Must the unique list keep first-seen order, or is any order fine?
  • How large is the input, and does it fit in memory?
  • Is the output for an API, a file format or a GPU buffer (which decides the index type)?

What a strong answer covers

  • A hash map from vertex to its index in unique, filled in one pass: O(n) expected time and O(u) extra memory.
  • Correct handling of the empty list, all-duplicate and all-unique inputs.
  • A round-trip test: decompress(*compress(v)) == v.
  • A note on float keys: exact equality versus quantizing to a tolerance, and the problems a tolerance brings (two points close to a third but not to each other).

Follow-ups

  • Merge vertices within a tolerance eps. How do you avoid comparing every pair (a spatial hash on a grid of cell size eps, checking neighboring cells)?
  • Vertices carry attributes (normal, texture coordinate). Deduplicate on the whole record.
  • The list is too large for memory: compress it in chunks or stream it.

Where it's asked

What it tests

hash map · arrays

Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding