bugl
bugl
HomeLearnPatternsPathsSearchPremium
HomeLearnPatternsPaths
HardTwo PointersLC 158

Read N Characters Given read4 II - Call Multiple Times

Given a file and assume that you can only read the file using a given method read4, implement a method read to read n characters. Your method read may be called multiple times. Method read4: The API read4 reads four consecutive characters from file, then writes those characters into the buffer array buf4. The return value is the number of actual characters read. Note that read4() has its own file pointer, much like FILE fp in C. Definition of read4: Parameter: char buf4 Returns: int buf4 is a destination, not a source. The results from read4 will be copied to buf4.

Asked at 8 companies
AmazonBloombergFacebook
Hints
  • 1.Think about which data structure fits best
  • 2.Consider the time complexity of your approach
  • 3.Look for patterns in the constraints
LeetCode