Back to problems

Allocate Unique File Names in an In-Memory Vault

Algorithm · Harvey · Medium

Design an in-memory file vault that tracks every name it has reserved. Given a sequence of creation requests, return the final reserved name for each request, preserving order. All requests operate in one shared namespace. The namespace is empty initially, and a reserved name can never be removed or renamed. If the requested name s is not reserved, assign s directly. If it is already reserved, append (1), (2), (3), ... to the end of s, and assign the earliest candidate that…

Checking your access…