This question evaluates a candidate's skills in file I/O and streaming algorithms, memory-efficient buffering, text encoding correctness (UTF-8), and robustness to system-level file semantics such as seekability, newline conventions, long-line handling, and log rotation.
Implement a utility that prints the last N lines of input. Requirements: handle both a regular seekable file and a non-seekable stream (stdin/pipe); support Unix LF, Windows CRLF, and classic Mac CR newlines; operate under tight memory (do not read the entire file); handle extremely long lines that exceed buffer size; preserve UTF-8 correctness when splitting by lines. Follow-ups: extend to tail -f (follow file growth), handle log rotation/truncation and symlinks, and support the '-c' option for the last N bytes. Provide data structures, algorithms, time/space complexity, and edge cases.