Interview Questions: Part 1
The questions they ask.
Coding interviews often start with questions about the basics, before any code. Short, clear answers show that you really understand the tools. Let's go through the ones that come up most.

- Interviews start with basics
- Short, clear answers
- The most common questions
List or dictionary?
What's the difference between a list and a dictionary? A list keeps items in order, by position, and finding a value means scanning, which is O of N. A dictionary stores key value pairs in a hash table, so looking up a key is O of one on average. Use a list for order, and a dictionary for fast lookup by key.
| key | value |
|---|---|
| List | ordered by position |
| Search a list | O(n) |
| Dictionary | key to value |
| Look up a key | O(1) average |
Stack or queue?
What's the difference between a stack and a queue? A stack is last in, first out, like a pile of plates. A queue is first in, first out, like a line at a shop. Stacks power undo, and depth first search. Queues power breadth first search, and task scheduling. In Python, use a list for a stack, and a deque for a queue.
| key | value |
|---|---|
| Stack | last in, first out |
| Queue | first in, first out |
| Stack uses | undo, DFS, brackets |
| Queue uses | BFS, scheduling |
Array or linked list?
When is a linked list better than an array? A linked list can insert or remove at the front in O of one, while an array has to shift everything. But an array can jump to any position in O of one, and a linked list has to walk there. Arrays also use the computer's memory cache better, so in practice, arrays usually win.
| key | value |
|---|---|
| Array index | O(1) |
| List index | O(n), walk there |
| Insert at front | array O(n), list O(1) |
| Usually | arrays win |
Summary
Know the trade offs. Lists keep order, dictionaries find keys fast, stacks are last in first out, and queues are first in first out. Next, more interview questions.
Key takeaways- List vs dict
- Stack vs queue
- Array vs linked list