Document and Layer Operations
Problem statement
Process operations on a collection of documents and layers. Document IDs and layer IDs are lowercase ASCII strings, and layer IDs are globally unique.
Each operation has one of these forms:
["createDocument", documentId]creates an empty document.["addLayer", documentId, layerId, value]creates a layer in the document.["renameLayer", layerId, newValue]changes a layer's value.["moveLayer", layerId, targetDocumentId]moves a layer to another document without changing its ID or value.["removeLayer", layerId]removes a layer.
After all operations, return every document ordered by document ID. Serialize a document as documentId{layerId=value,...}, with its remaining layers ordered by layer ID. Include empty documents as documentId{}.
Function
processDocumentLayers(operations: String[][]) → String[]Examples
Example 1
operations = [["createDocument","draft"],["addLayer","draft","title","hello"],["renameLayer","title","welcome"]]return = ["draft{title=welcome}"]The layer title remains in draft with its updated value.
Example 2
operations = [["createDocument","a"],["createDocument","b"],["addLayer","a","z","green"],["addLayer","a","m","blue"],["moveLayer","z","b"]]return = ["a{m=blue}","b{z=green}"]Moving z removes it from document a and preserves it in document b.
Example 3
operations = [["createDocument","doc"],["addLayer","doc","x","one"],["removeLayer","x"]]return = ["doc{}"]The document remains after its only layer is removed.
Constraints
1 <= operations.length <= 200000.- At most
100000documents and200000layers are created. - Every document ID and layer ID is unique when created.
- Every non-create operation references an existing document or layer as required.
- IDs and values are non-empty lowercase ASCII strings of at most
40characters and do not contain{,},=, or,.