Loading section...
Common Bugs and Python Pitfalls
Concepts: pyStackBugs, pyQueuePerf, pyRecursionLimit
These are the bugs that experienced engineers make in interviews when they are moving fast. Every one of them is preventable if you know to look for it. Read this section and burn it into your muscle memory before your interview. Bug 1: list.pop(0) Instead of deque.popleft() This is the most common Python-specific mistake. list.pop(0) works correctly but is O(n). In a BFS over a graph with V vertices and E edges, using list.pop(0) makes BFS O(V * (V + E)) instead of O(V + E). On a graph with 10,000 nodes, that is 10,000x slower. The interviewer will catch this. Say 'I am using deque for O(1) popleft' before you even write the code. Bug 2: Popping from an Empty Stack An empty stack pop crashes with IndexError. In the balanced brackets problem, a close bracket with an empty stack means the i