darrenfu/LeetcodePy

Lyft

Closed this issue · 1 comments

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:

  1. It could return empty results if reaches the end.
  2. page number starts from 0.
  3. page size is a fixed number, let's say 10.

Follow-up:

  1. What if page size is a variant?
  2. 158. Read N Characters Given Read4 II - Call multiple times What if the fetcher is stateful? Every time you call fetch, it will continue with the previous offset. If it reaches the max_results, no records will be returned anymore unless you recreate another fetcher instance.
  1. Be careful with the page number 0.
  2. Be careful with the edge case of the remainder elements in the last page.

Follow up:

  1. Every time you call fetch, check the page size to see whether it reaches the end.
  2. Use two instance variables self.local_offset and self.pagenum to store the previous fetch states.