FastPrepRead N Characters with read4 Across Multiple Calls
Problems/Read N Characters with read4 Across Multiple Calls

Read N Characters with read4 Across Multiple Calls

Bloomberg LP logoBloomberg LP● HardNEW GRADONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The Bloomberg new-grad first virtual-onsite report names this well-known problem. It says the first solution used O(n) space, and the candidate was pushed to use O(1) extra buffering. Our version keeps the state across several calls, the read4 over-read, the end-of-file behavior and the fixed four-character buffer. The calls come as a finite list.

A stateful reader consumes characters from file from left to right. Its only low-level operation is read4, which consumes up to four remaining characters. Characters fetched by read4 but not returned by the current call must remain buffered for later calls.

The array reads describes consecutive calls to read(n) on the same reader. For each value n, return a string containing up to n next unread characters, or fewer when the file reaches end-of-file.

Return one string for every requested call, preserving the reader state across all calls.

Function

readAcrossCalls(file: String, reads: int[]) → String[]

Examples

Example 1

file = "abcdef"reads = [1,3,4]return = ["a","bcd","ef"]

The first call returns one character while retaining the other fetched characters. The next call continues at b, and the last call receives the two remaining characters.

Example 2

file = "abc"reads = [4,1]return = ["abc",""]

The first call reaches end-of-file after three characters. Every later call returns an empty string.

Example 3

file = "abcdefghijkl"reads = [5,2,5]return = ["abcde","fg","hijkl"]

All three calls share one reader, so the chunks concatenate to the original file without duplication or omission.

Constraints

  • 0 <= file.length <= 100000.
  • 1 <= reads.length <= 100000.
  • 0 <= reads[i] <= 100000.
  • The sum of all values in reads is at most 100000.
  • file contains printable ASCII characters other than line breaks.

More Bloomberg LP Onsite Interview questions

  • Pascal's TrianglePHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
  • Valid Triangle NumberPHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
  • Collatz Conjecture with Shared MemoizationPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Word SearchOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • N-ary Index-Path Encoder and DecoderPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Top K Frequent WordsONSITE INTERVIEW · Seen Nov 2026
  • Trapping Rain WaterPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Design Browser HistoryPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Mutable Stock Price Top KPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Add Two Numbers IIPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026

Similar questions at other companies

  • Deterministic Word Guess SolverAtlassian · ONSITE INTERVIEWAtlassian interview questions
  • Hybrid Run-Length and Bit-Packing EncoderDatabricks · ONSITE INTERVIEWDatabricks interview questions
  • Query Log MatchDatadog · PHONE SCREEN · ONSITE INTERVIEWDatadog interview questions
  • Digit-Coded Card ValidationCapital One · ONSITE INTERVIEWCapital One interview questions
  • Compress Editor Actions into Operational Transform OperationsReplit · OA · PHONE SCREEN · ONSITE INTERVIEW
  • Path Leaf Character IteratorGoogle · ONSITE INTERVIEWGoogle interview questions
  • Trace Events from Stable Whole-Stack StatesAnthropic · ONSITE INTERVIEWAnthropic interview questions
  • Retry with an Attempt LimitOracle · ONSITE INTERVIEWOracle interview questions
  • Extract Error Log ContextFlexTrade · ONSITE INTERVIEWFlexTrade interview questions
  • Hex Dump FormatterWaymo · ONSITE INTERVIEWWaymo interview questions

Bloomberg LP interview experiences

  • Bloomberg AI-Assisted Coding Round, All Levels: 14 Experiences
  • Bloomberg SWE Intern Interview Questions: 68 Questions
  • Bloomberg Interview Questions, Level Not Reported: 65 Questions
  • Bloomberg Experienced Design & More: 126 Questions (Part 2 of 2)
  • Bloomberg Experienced SWE Interviews: 167 Questions (Part 1 of 2)
  • Bloomberg New Grad Coding Questions: 121 Questions (Part 2 of 2)
All Bloomberg LP interview questionsSee Bloomberg LP hiring insights
Saved
class Solution {
    public String[] readAcrossCalls(String file, int[] reads) {
        // Write your code here.
    }

}
Checking account…