Library
Practical coding under time pressure
Code graded like production code. A spec that grows while you build it, concurrency done right, and the dynamic programming that still shows up.
A spec that grows
Concurrency
Dynamic programming
Practice questions
15The four-level online coding test
- 1.Level 3 adds timestamps to every operation, and your level 1 stored one bare value per key. What's the best first move?
- 2.A record is written at 40 with a TTL of 20. Which check keeps it alive for exactly the 20 seconds it was given?
- 3.At 10 you take a snapshot. Task a has no deadline, b is due at 10 and c at 12, and nothing has deleted expired tasks. How many pending tasks should the snapshot report?
- 4.A timer ends at 130. It's saved at 110 and restored at 500, and the spec says a restored timer keeps the time it had left. When does it end now?
- 5.Snapshots exist at 2, 4 and 6, and a restore asks for the state as of 5. Your loop returns the first snapshot whose time is at or before 5. What does it return, and what's right?
A multithreaded web crawler
- 1.Each fetch on the 41-page site waits about 58 ms. One page at a time took 2.36 s, and an 8-thread pool took 0.35 s. Why doesn't the GIL stop that?
- 2.You start a
threading.Threadfor every new link instead of using a pool. On the test's 41-page site withmax_workers=4, how many fetches were in flight at the peak? - 3.A page links to
http://example.com/b#top. What should go intoseenand get fetched? - 4.The crawl starts at
http://example.com/. Which check keeps it on that host? - 5.One page's fetch raises
ConnectionError, and your coordinator callsfuture.result()with notry. What happens?
Coin change with dollar amounts
- 1.What does
int(0.29 * 100)return? - 2.Coins of 10 and 25 cents, amount 30 cents. What does greedy return?
- 3.You write
count_wayswith the amount loop outside and the coin loop inside. What does it return for 10 cents from coins of 1, 5 and 10? - 4.The amount is 500 dollars and there are 6 coin values. About how many inner-loop steps does the bottom-up
min_coinstake? - 5.You memoize the recursion with
functools.cacheand try the 1-cent coin first. What happens on the 500-dollar test with Python's default settings?