Software Engineer • Senior-Level
Software Engineer • Senior-Level
High QualityInterview Summary
I had to reverse a file byte by byte using less memory than the file itself, then make the operation resumable after a process crash or power loss. The tricky case was a crash after the output reached disk but before the checkpoint did. In that window, resuming from the last checkpoint could duplicate bytes that were already in the output.
Interview Details
Systems Programming — Reverse a File Larger Than Memory
The input was a single large file, and I had to write its bytes in reverse order to a separate destination file. My approach was to get the file size, start at the last chunk, and work backward with positional reads such as pread or ReadAt. I reversed the bytes within each chunk and wrote them sequentially through a buffered writer.
The last input chunk was the first one I would write, so its actual length mattered. With 64 KB chunks, for example, that first read could return fewer than 64 KB. I would reverse only the bytes read, reuse the same buffer across iterations, and handle a zero-byte input by producing an empty
Unlock Full Details
Create a free account to unlock this interview experience report.