Map of full paths
Time O(L) per call for string work Space O(total path length)paths: HashMap from full path to value. createPath checks the path is new and the parent is either "" or present.
import java.util.*;
class FileSystem {
private final Map<String, Integer> paths = new HashMap<>();
public FileSystem() {}
public boolean createPath(String path, int value) {
if (path.isEmpty() || path.equals("/") || paths.containsKey(path)) return false;
String parent = path.substring(0, path.lastIndexOf('/'));
if (!parent.isEmpty() && !paths.containsKey(parent)) return false;
paths.put(path, value);
return true;
}
public int get(String path) { return paths.getOrDefault(path, -1); }
}Verdict: Simplest correct design.