gary@interview:~/interview/coding/158-read-n-chara….md$
$ cat ./coding/158-read-n-characters-given-read4-ii-call-multiple-times.md
[Coding]

158. Read N Characters Given Read4 II - Call multiple times

────────────────────────────────────────────────────────────

158. Read N Characters Given Read4 II - Call multiple times

# The read4 API is already defined for you.
# def read4(buf4: List[str]) -> int:

class Solution:
    def __init__(self):
        self.queue = collections.deque()

    def read(self, buf, n):
        i = 0
        while i < n:
            buf4 = [''] * 4 
            _ = read4(buf4) 
            self.queue.extend(buf4)
            count = min(len(self.queue), n - i) 
            if not count:
                break
            buf[i:] = [self.queue.popleft() for _ in range(count)]
            i += count
        return i

--tags#Other
$ ls ./coding/ | grep -v 158-read-n-characters-given-read4-ii-call-multiple-times
265. Paint House II256. Paint House143. Reorder List1762. Buildings With an Ocean View
← cd ../codingcd ~