The coding portion covered two independent tasks.
-
Implement a simplified layer editor for a design tool. The editor maintains an ordered list of layer IDs. Support the following operations:
-
addLayer(id, index)
: insert a new layer at the given position.
-
removeLayer(id)
: remove an existing layer.
-
moveLayer(id, newIndex)
: move a layer to a new position.
-
undo()
: revert the most recent committed edit.
-
redo()
: re-apply the most recently undone edit.
-
beginBatch()
and
endBatch()
: all edits inside a batch must be treated as one atomic history entry.
Assume batches are not nested. If a new edit is applied after an undo(), the redo history must be cleared. undo() and redo() must restore the exact previous layer ordering.
-
Given a 2D grid containing
L
for land and
W
for water, count how many connected land regions exist. Two land cells belong to the same region if they share a side. Write an algorithm and analyze its time and space complexity.