[Solution] read7 | Microsoft Interview Question
This problem was asked Microsoft.
read7() method that returns
7 characters from a file, implement
readN(n) which reads
For example, given a file with the content “Hello world”, three
read7() returns “Hello w”, “orld” and then “”.
Idea behind the solution
The solution for this problem is simple, we just need to read 7 letters as much as possible. As long as
total_letters_read + 7 < total_needed we keep reading with
read7(). At the end, we read another 7 letters and throw away the end of the string we don't need (in case we read more than asked).
Please check the Solution.java snippet for the solution.
This solution originally posted at: Github by @Murillo2380