-
Notifications
You must be signed in to change notification settings - Fork 39
/
problem_16.py
37 lines (28 loc) · 868 Bytes
/
problem_16.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
def coding_problem_16(length):
"""
You run a sneaker website and want to record the last N order ids in a log. Implement a data structure to
accomplish this, with the following API:
record(order_id): adds the order_id to the log
get_last(i): gets the ith last element from the log. i is guaranteed to be smaller than or equal to N.
You should be as efficient with time and space as possible.
Example:
>>> log = coding_problem_16(10)
>>> for id in range(20):
... log.record(id)
>>> log.get_last(0)
[]
>>> log.get_last(1)
[19]
>>> log.get_last(5)
[15, 16, 17, 18, 19]
>>> log.record(20)
>>> log.record(21)
>>> log.get_last(1)
[21]
>>> log.get_last(3)
[19, 20, 21]
"""
pass
if __name__ == '__main__':
import doctest
doctest.testmod(verbose=True)