Facebook | Implement a Database Cursor | Phone Screen
Company: Meta
Role: e3, e4
Interview Stage: Phone Screen
Location: unknown
Year: unknown
Original Post Content:
Suppose you are designing a cursor-type system for a backend database and you are given this method:
def next10Items() -> return type [list]:
# returns the next 10 items in the database if available, otherwise returns the remaining items left.
# If doesn't exist, then returns 0.
# e.g. 16 total items first time it's called, we get items 0-9, second time it's called we get items 10-16, last time it's called we get empty list []
implement a method nextItems(n) that when given an integer n, will return the n items in a list.
For example, with 50 total items.
One test case:nextItems(20) should give us items 0-19,
Second test case:nextItems(35), nextItems(20) should give us items 0-35, then when called again should give us 36-50. If called a third time with nextItems(5) return []
Ignore negative numbers.