Bounded Console Output Buffer for Long-Running Repls

Last updated: November 29, 2026

Quick Overview

Implement a console buffer that receives arbitrary text chunks from a running process and keeps only the most recent lines, capped both by line count and by total bytes, while correctly handling lines split across chunks.

Replit
Coding & Algorithms
Software Engineer
Replit
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Easy

0

0

0 solved


Implement a console buffer that receives arbitrary text chunks from a running process and keeps only the most recent lines, capped both by line count and by total bytes, while correctly handling lines split across chunks.

Every Repl streams stdout to the browser console, and a server that logs forever must not grow memory without bound on either side. The interviewer checks that you handle partial lines across chunk boundaries, keep a running byte count, and think about one giant line with no newline.

What the Interviewer Expects
  • Buffers a trailing partial line until its newline arrives
  • Evicts from the front with a deque in O(1) per line
  • Tracks byte size incrementally instead of recomputing
  • Enforces both the line cap and the byte cap
  • Handles a single line larger than the byte cap
Key Topics to Cover
ring buffer
deque
streaming
chunk boundaries
memory bounds
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How would you support ANSI escape codes such as carriage return progress bars?
  • How would a client that reconnects ask for only the lines it missed?
  • How would you handle invalid UTF-8 split across two chunks?
  • Where should this buffer live: container, server, or browser?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

write(chunk) may be called with any slice of output: half a line, many lines, or a megabyte with no newline. snapshot() returns retained lines plus the in-progress line. Keep at most max_lines c...

High-Level Design

A deque of complete lines plus a running byte total, and a partial string for text after the last newline. On write, prepend partial, split on newlines, keep the last piece as the new partial, a...


Submit Your Answer
Markdown supported

Related Questions