FastPrepClayWorkspace Resource Tree
Problems/ClayWorkspace Resource Tree

ClayWorkspace Resource Tree

Goldman Sachs logoGoldman Sachs● HardFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A Goldman Sachs senior-software-engineer screen asks for an in-memory ClayWorkspace resource tree that supports create, list, recursive delete, and move. It does not give the path syntax, return values, ordering, or the rules for invalid operations. This version takes commands with absolute paths. Our version is about 84% the same as the reported question.

You manage an in-memory tree of resources. The root of the tree is /. Every command uses full paths that start at the root, written in standard form with names joined by single slashes, such as /team/api. A resource name is never empty and never contains a space or a /.

  • create path: make a new resource at that path. This works only if its parent exists and the name is not already taken there.
  • list path: return the names of the direct children of that resource, sorted as strings in lexicographic order and written as [a,b].
  • delete path: remove that resource and everything under it.
  • move source destinationParent: move the source resource, with everything under it, into the destination. It keeps its name.

A create, delete or move that works returns OK. An invalid command returns ERROR. These are invalid: a missing path, a name that is already taken, deleting or moving /, moving a resource into itself or anything under it, and moving into a destination that already has a child with the same name. Return one result for every command.

Function

processWorkspace(operations: String[]) → String[]

Examples

Example 1

operations = ["create /team","create /team/api","create /team/web","list /team","move /team/web /","list /","delete /team","list /"]return = ["OK","OK","OK","[api,web]","OK","[team,web]","OK","[web]"]

After the creates, /team has the children api and web. Moving /team/web to / puts web next to team at the root. Deleting /team also deletes api under it, so the last list shows only web.

Example 2

operations = ["create /a","create /a","create /missing/x","delete /","move /a /a","list /"]return = ["OK","ERROR","ERROR","ERROR","ERROR","[a]"]

The first create works. Creating /a again fails because the name is taken. Creating /missing/x fails because its parent does not exist. Deleting / fails because the root cannot be deleted. Moving /a into itself fails too. Each failure returns ERROR, and the final list of the root still shows only a.

Constraints

  • 1 <= operations.length <= 100000
  • Every path starts with /. It ends with a slash only when the path is / itself. It has at most 100 segments, where a segment is one name between slashes.
  • All paths together have at most 2000000 characters.
See Goldman Sachs hiring insights
Saved
class Solution {
    public String[] processWorkspace(String[] operations) {
      // write your code here
    }
}
Checking account…