Search topics...
All Problems

Read N Characters Given Read4 II (call multiple times)

Solution Approach
Was this helpful?
Hardos-flavorExpected: O(n) time, O(1) space

Problem

Given read4, implement read(buf, n) that may be called multiple times, reading n characters each time.

Example 1:

Input: file = "abc"
       read(buf, 1) -> returns 1, buf = "a"
       read(buf, 2) -> returns 2, buf = "bc"
       read(buf, 1) -> returns 0, buf = ""

Example 2:

Input: file = "abc"
       read(buf, 4) -> returns 3, buf = "abc"
       read(buf, 1) -> returns 0, buf = ""
Reference solution unlocks after your first submission
Loading...