Filesystem Hash Tree
Reported by candidates from Cursor's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The Cursor OA reported in September 2026 is a Merkle tree in disguise. You get flat parallel arrays of paths, types and contents, and you have to rebuild the filesystem, hash every node bottom-up with FNV-1a, and print path=hash lines. It's a tree problem, but nobody hands you a tree. You build it from path strings first. The hashing is mechanical. The tricky part is ordering and structure at 100000 nodes. If you blank mid-assessment, StealthCoder runs invisibly as a safety net while you work the problem.
The problem
Build the hash tree for one finite rooted filesystem. The filesystem is described by three parallel arrays: paths[i] is a normalized absolute path. The root path is /. types[i] is either FILE or DIRECTORY. contents[i] is the UTF-8 text of a file and is the empty string for a directory. Hash every node with 64-bit FNV-1a. Start from offset basis 0xcbf29ce484222325. For each input byte, XOR it into the current value and multiply by prime 0x100000001b3, keeping only the low 64 bits. Render the result as exactly 16 lowercase hexadecimal digits. A file's hash is the FNV-1a hash of its UTF-8 content bytes. A directory's hash is the FNV-1a hash of the ASCII bytes formed by concatenating the 16-digit hashes of its direct children in lexicographic child-name order. An empty directory therefore hashes the empty byte sequence. Return one string path=hash for every node, sorted in lexicographic path order. Function hashFileSystem(paths: String[], types: String[], contents: String[]) → String[] Examples Example 1 paths = ["/","/docs","/docs/a.txt","/docs/b.txt"] types = ["DIRECTORY","DIRECTORY","FILE","FILE"] contents = ["","","hi","bye"] return = ["/=2ff0bacda65bbb3f","/docs=f065768922a4a2f1","/docs/a.txt=08ba5f07b55ec3da","/docs/b.txt=008a2f19137d94c3"] The two file contents are hashed first. The directory /docs concatenates the hash of a.txt before the hash of b.txt, then the root hashes the resulting /docs hash. Example 2 paths = ["/","/empty","/readme"] types = ["DIRECTORY","DIRECTORY","FILE"] contents = ["","","hello"] return = ["/=e4e38674a4d63445","/empty=cbf29ce484222325","/readme=a430d84680aabd0b"] The empty directory hashes the empty byte sequence. The root concatenates the hash of child empty before the hash of child readme. Example 3 paths = ["/","/z.txt","/a","/a/x.txt"] types = ["DIRECTORY","FILE","DIRECTORY","FILE"] contents = ["","same","","same"] return = ["/=d8493d74efdbb133","/a=a303de6ee1bde850","/a/x.txt=097b5e18bf93ef5b","/z.txt=097b5e18bf93ef5b"] Equal file contents produce equal file hashes. Directory /a hashes its one child's hash, and the root processes child name a before z.txt. Constraints 1 <= paths.length = types.length = contents.length <= 100000. paths contains exactly one / root and one unique normalized absolute path per node. Every non-root parent path appears in paths. Every path component contains only lowercase English letters, decimal digits,., _, and -. Every types[i] is FILE or DIRECTORY. A file has no descendants. Its content may be empty. A directory has empty contents[i]. Each path contains at most 500 UTF-8 bytes, and the total file-content size is at most 1000000 UTF-8 bytes.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The data structure is a tree built from a hash map. Map each path to a node, then derive the parent by cutting at the last slash (the parent of a top-level path is /). Attach each node to its parent's child list. Sort each child list by child name, which is the last path component. Then compute hashes post-order. Do it iteratively, because a deep chain of 100000 directories will blow a recursive stack. A file hashes its content bytes. A directory hashes the concatenated 16-digit hex strings of its children. Pitfalls: hashing characters instead of UTF-8 bytes, forgetting to zero-pad to 16 digits, not masking to 64 bits (Python ints won't overflow for you), and sorting by full path rather than child name. Sort final output by path. If the hashing or iterative order trips you up live, StealthCoder is the hedge that gets you unstuck.
Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.
You can drill Filesystem Hash Tree cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made for the candidate who got the OA invite this morning and has 72 hours, not six months.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Cursor's OA.
Cursor reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Filesystem Hash Tree FAQ
What's the core trick in Filesystem Hash Tree?+
Build parent-to-children lists from the flat path array using a hash map, then hash post-order. Children must be sorted by name before concatenating their hashes. The FNV-1a function itself is just XOR then multiply, masked to 64 bits.
How hard is this Cursor OA question really?+
Medium. No clever algorithm is needed, but there are many small ways to lose points: byte vs character handling, hex padding, 64-bit masking, and sort order. Careful implementation matters more than insight.
Should I use recursion for the hash computation?+
Be careful. Paths can nest up to the 100000 node limit, so a chain-shaped tree can overflow the recursion stack. Process nodes iteratively, for example in order of decreasing path depth, so children are always hashed before their parent.
How do I sort children correctly?+
Sort by the child's own name, the last path component, not the full path. Within one parent, the shared prefix is identical, so it matches, but using names is cleaner. Final output sorts all path=hash strings by path in lexicographic order.
How do I prepare for this in 48 hours?+
Write FNV-1a from memory and check it against Example 2, where the empty directory must give cbf29ce484222325. Then practice building a tree from path strings and a post-order pass. Test with an empty directory and a deep chain.