Multi-Call Chunked Stream Reader

You are building the tailer for an append-only telemetry archive. The archive is far too large to load, and the storage driver exposes exactly one door: a four-slot crate. Every call to the primitive read4 loads the next unread characters of the source into a crate of capacity four and reports how many characters it managed to copy. Consumers of the log, however, request convenient sizes: eighty characters here, three there, sometimes zero at all. Your task is to implement the chunked reader so those consumers never notice the four-character granularity hiding underneath.

Unlike the single-shot version of this task, read is invoked many times on the same reader logically. Every call resumes where the previous call stopped. That persistence is what makes the problem hard: characters fetched by read4 but not yet delivered must stay alive between calls.

On this platform the multi-call session is exposed as a deterministic functional dispatch solve(file, reads) that returns an array of strings, one per read call, so the judge can verify every delivered character without relying on class instance state.

The provided primitive

The judge owns the hidden source string and the logical reader exposes one primitive:

int read4(char[] buf4)
  • Copies the next unread characters of the source into buf4, at most four per call.
  • Returns the number of characters actually copied; a return value of 0 means the source is fully drained.
  • The stream moves forward only. There is no seek, no rewind, and no peek.

What you implement

string[] solve(string file, int[] reads)

Given the hidden file string and an array reads where reads[i] is the n for the i-th logical read call, return an array out where out[i] is exactly the substring that call would have returned. out[i] is at most reads[i] characters; an empty string means nothing was copied.

  • Requests are processed sequentially on one logical reader instance and each call continues from where the previous call stopped.
  • Overshoot characters pulled by read4 beyond the current request must be delivered by a later call. Losing them or delivering them twice both count as corruption.
  • A call with n = 0 must return an empty string without consuming anything.
  • read4 must be the only way the reader obtains characters from the source.
Examples
Input: ["frontendx",[5,4]]
Output: ["front","endx"]
Hints

Multi-Call Chunked Stream Reader

You are building the tailer for an append-only telemetry archive. The archive is far too large to load, and the storage driver exposes exactly one door: a four-slot crate. Every call to the primitive `read4` loads the next unread characters of the source into a crate of capacity four and reports how many characters it managed to copy. Consumers of the log, however, request convenient sizes: eighty characters here, three there, sometimes zero at all. Your task is to implement the chunked reader so those consumers never notice the four-character granularity hiding underneath.