PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches
|Home/Coding & Algorithms/Confluent

Implement tail N lines

Last updated: May 15, 2026

Quick Overview

This question evaluates understanding of file I/O, memory-efficient streaming and buffering techniques, handling of multibyte text encodings and newline conventions, and robustness against edge cases like extremely long lines.

  • Medium
  • Confluent
  • Coding & Algorithms
  • Software Engineer

Implement tail N lines

Company: Confluent

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: Medium

Interview Round: Technical Screen

Implement a function tail(path: string, N: int) that prints the last N lines of a potentially multi-GB text file without loading the whole file into memory. Assume variable-length lines and unknown line count. Explain and implement approaches for (a) random-access files using seeking/backward scan or a fixed-size ring buffer, and (b) an unbounded input stream where seeking is impossible, maintaining only O (N) memory. Discuss handling of UTF-8 multibyte characters, files missing a trailing newline, different newline conventions, and extremely long lines. Provide time and space complexities and key test cases.

Quick Answer: This question evaluates understanding of file I/O, memory-efficient streaming and buffering techniques, handling of multibyte text encodings and newline conventions, and robustness against edge cases like extremely long lines.

Related Interview Questions

  • Implement Tail and Find Monster Cost - Confluent (medium)
  • Solve Signature, File, and Queue Problems - Confluent (medium)
  • Process pod logs with global increments and pop-min - Confluent (easy)
  • Implement File Tail and Sensor Health - Confluent (medium)
  • Rank songs by pairwise user preferences - Confluent (medium)
Confluent logo
Confluent
Sep 6, 2025, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
23
0

Implement a function tail(path: string, N: int) that prints the last N lines of a potentially multi-GB text file without loading the whole file into memory. Assume variable-length lines and unknown line count. Explain and implement approaches for (a) random-access files using seeking/backward scan or a fixed-size ring buffer, and (b) an unbounded input stream where seeking is impossible, maintaining only O (N) memory. Discuss handling of UTF-8 multibyte characters, files missing a trailing newline, different newline conventions, and extremely long lines. Provide time and space complexities and key test cases.

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Confluent•More Software Engineer•Confluent Software Engineer•Confluent Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.