Lyft
Closed this issue · 1 comments
darrenfu commented
12/09/2019
157. Read N Characters Given Read4
Given a fetch_by_page(page)
method, implement a fetcher.fetch(nums_of_results)
method using this method. Write some test cases to verify it.
Note:
- It could return empty results if reaches the end.
- page number starts from 0.
- page size is a fixed number, let's say 10.
Follow-up:
- What if page size is a variant?
- 158. Read N Characters Given Read4 II - Call multiple times What if the
fetcher
is stateful? Every time you callfetch
, it will continue with the previous offset. If it reaches the max_results, no records will be returned anymore unless you recreate anotherfetcher
instance.
darrenfu commented
- Be careful with the page number 0.
- Be careful with the edge case of the remainder elements in the last page.
Follow up:
- Every time you call
fetch
, check the page size to see whether it reaches the end. - Use two instance variables
self.local_offset
andself.pagenum
to store the previousfetch
states.