Figma interview question
Document layers with property edits, undo, batched undo and redo
- Company:
- Figma
- Round:
- Technical
- Type:
- Coding
- Difficulty:
- Hard
- Reported:
- October 19, 2026
Problem
A design document contains layers. Each layer has an id and a map of properties such as color or shape. Build a Document class. The interview adds the operations in stages, and the final class supports all of them:
add_layer(layer_id, props)creates a layer with the given properties, andget_layer(layer_id)returns a copy of a layer's properties.apply(layer_id, prop, value)sets one property immediately.undo()reverts the most recent change. If the property did not exist before that change, reverting it removes the property again.- Follow-up 1:
commit_batch()groups every change applied since the previous commit, so that a singleundo()reverts the whole group. Changes still take effect as soon as they are applied. - Follow-up 2:
redo()re-applies the most recently undone change or group, and any newapplyclears the redo history.
Keep memory low: setting the same property many times within a batch should not leave redundant history behind, and repeated string values should not be stored as many separate copies.
Some behavior is left open; settle it with the interviewer. Any consistent choice is accepted, and the examples below avoid these cases:
- how
undotreats changes applied after the last commit (keeping the first-stage behavior, one change at a time, is the natural reading); - what
undoandredodo or return when there is nothing to undo or redo; - whether adding a layer is part of the undo history;
- what happens for an unknown layer id or for an id that is added twice.
Example 1
Input: add_layer("a", {"color": "red"}),
apply("a", "color", "blue"), commit_batch(),
apply("a", "color", "green"), apply("a", "color", "black"), apply("a", "shape", "circle"), commit_batch(),
undo(), get_layer("a"), undo(), get_layer("a"), redo(), get_layer("a")
Output: get_layer("a") -> {"color": "blue"}, then {"color": "red"}, then {"color": "blue"}
The second batch changed the color twice and added a shape, and one undo() reverts all of it. The next undo() reverts the first batch, and redo() re-applies it.
Example 2
Input: add_layer("b", {}), apply("b", "x", 1), commit_batch(),
apply("b", "x", 2), apply("b", "y", 3), commit_batch(),
undo(), get_layer("b"), undo(), get_layer("b")
Output: get_layer("b") -> {"x": 1}, then {}
Undoing the second batch restores x to 1 and removes y, which did not exist before it. Undoing the first batch removes x.
Constraints
- Property names are strings; values can be of any type.
- No limits on the number of layers, properties or operations are given.
Reported by candidates or drawn from publicly available sources, and rewritten in our own words. Pathwise Prep does not publish confidential assessment content. Report a concern