← Questions
Compress a vertex list into unique vertices and indices
0
I was asked this
No reports yet. Sign in to say where you were asked it.
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 inrange(len(unique)).
Clarifying questions
- Are coordinates integers or floats? If floats, are
0.0and-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 sizeeps, 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
- Applied Intuition · Technical phone screen · Last asked Feb 202645 min · Live coding in CoderPad; the language can be fixed by the role (Python, C++, or C for embedded)
What it tests
No official answer yet. Write yours on the right and run it.
Nothing published yet.
Sign in to submit your code; every attempt is kept here.
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
