The file system question that's been going around the forum. Here's my report.
Similar to a file system — implement two functions:
addFile(String path): given a string like"path/to/somewhere/file.txt", store this file.getFile(String path): given"path/to/somewhere", return the content offile.txt; given"path/to", return the folder"somewhere".
There wasn't much of a self-introduction, we jumped right in. The interviewer was American, but his English was honestly hard to follow. He explained the problem once and I didn't catch it, so I just read it myself — pretty blunt intro. I just added a dict of dict and passed it down level by level, that's it.
Follow-up 1: each level can have at most 5 things (including folders and files) — once the current level's keys exceed 5, you can't add a new folder or file, even for just one new path. Just brute-force count the keys.
Follow-up 2: if there's a duplicate name, you need to handle it the way an OS does — file.txt, file(1).txt, file(2).txt. Just parse it (split around the ".") and maintain a counter that increments. One test case was add(file.txt), add(file.txt), add(file(1).txt), and the expected result was file.txt, file(1).txt, file(1)(1).txt. The interviewer struggled with this test case himself for a while, then after running it asked me if I understood what these test cases were checking. This requirement was never mentioned the whole time — he didn't explain when I asked, and he didn't say anything while he was fumbling through writing it either (how was I supposed to know what he wanted?). But my answer was correct.
There was also a follow-up on how to tell if two files are the same. Thanks to the forum write-ups, I'd prepared for this one — I answered with file hashing, like SHA-256 and MD5.
Passed.
Discussion
Loading comments…