Software Engineer • Staff-Level
Software Engineer • Staff-Level
High QualityInterview Summary
I worked through two filesystem problems: reversing a file too large for memory and lowercasing every directory name beneath a given root. The file problem hinged on what to do when the output reached disk before its checkpoint. The renaming problem had a different trap: on a case-insensitive filesystem, checking whether a destination exists can make a directory appear to collide with itself.
Interview Details
Coding: Reverse a Large File and Resume After a Crash
I had to write a byte-reversed copy of a file that was much larger than available memory. My approach was to read fixed-size chunks from the end of the source toward the beginning, reverse the bytes in each chunk, and write them sequentially to the destination. I could reuse one buffer throughout, provided I reversed only the bytes actually read. The final input chunk could be short, and an empty source still needed to produce an empty destination.
The recovery requirement introduced a subtle failure window. Suppose I flushed and synced a batch of output, then lost power before recording the new checkpoint. On restart, the old checkpoint would tell me to replay that batch. Opening the output in append mode would duplicate bytes that were already on disk.
I would recover at the committed byte offset, accounting for the short chunk written at the beginning of the output. I could truncate the destination to that offset, seek there, and resume. To update the checkpoint safely, I would sync the output first, write and sync a temporary checkpoint, rename it over the previous
Unlock Full Details
Create a free account to unlock this interview experience report.