The Python kit
The standard-library moves that save minutes in the room, from Counter and heapq to locks, queues, process pools, asyncio and fsync, each as the slow way and the fluent way side by side.
Is it cheating to use the standard library in an interview?
No, and reaching for it is usually the signal the interviewer wants. Using Counter instead of building a dictionary by hand says you know the library you work in, and it buys back the minutes you need for the follow-ups. The one time to be careful is when the library call is the thing being tested: if the question is about heaps, reaching for heapq is right, but reaching for it and being unable to say what a sift-down does is not.
Will an interviewer ask me to implement these by hand?
Sometimes, and almost always for the combinatorial ones. Writing combinations or permutations as a recursion is a standard question in its own right, so know how to do both: call itertools in the solution, and be ready to write the six-line recursive version if asked. The same goes for a heap, for binary search, and for a hash map. Use the library, understand the internals.
Which of these change the complexity, and which only save typing?
Four change it outright: a deque instead of list.pop(0) turns a queue from O(n) per pop into O(1); joining a list of strings instead of repeated concatenation turns quadratic string building into linear; a bisect instead of a scan turns a lookup from O(n) into O(log n); and caching a recursion turns exponential into polynomial. The rest, such as enumerate, tuple unpacking and sort keys, cost the same to run and save you time and mistakes while writing.
Should I write everything as a comprehension?
Up to one comprehension with one condition. Past that the interviewer has to decode it while you talk, and anything they cannot read quickly works against you. A nested comprehension with two conditions and a conditional expression is the most common way I’ve seen people lose the room while writing correct code. When a loop is clearer, write the loop.
What about numpy, sortedcontainers, or other third-party libraries?
Assume they are not available. Most interview environments give you the standard library only, and a solution built on sortedcontainers.SortedList usually dodges exactly the data structure the question was about. If the answer really wants a sorted multiset, say that a balanced tree or a skip list is what you would use in production, then build what you need from a heap, a sorted list with bisect, or two heaps.
Threads, processes or asyncio: which should I reach for in a systems round?
Threads when the work waits on blocking I/O and the libraries are ordinary blocking ones. asyncio when there are many connections and the libraries are async. Processes when the work is CPU-bound pure Python, because in the default CPython build only one thread runs Python bytecode at a time. Say the reason out loud with the choice; the reason is what the interviewer is listening for.
What is the difference between flush and fsync?
flush moves bytes from the buffer inside your Python process to the kernel, which is enough to survive your process crashing. os.fsync asks the kernel to write its copy to the disk, which is what survives the machine going down. The order is f.write, then f.flush, then os.fsync(f.fileno()), and you tell a caller their data is saved only after the last one returns.