File tree Expand file tree Collapse file tree 2 files changed +60
-39
lines changed
Expand file tree Collapse file tree 2 files changed +60
-39
lines changed Original file line number Diff line number Diff line change 11.vscode
2+ misc
23
34TODO.md
Original file line number Diff line number Diff line change 11# Python for coding interviews
22
33
4- ## Time complexity
4+ ## Primitive Types
5+ TODO
6+
7+
8+ ## Arrays
9+ TODO
10+
11+
12+ ## Strings
13+ TODO
514
615
716## Stacks
817``` python
9- stack = []
18+ >> > stack = []
1019
11- stack.append(1 )
12- stack.append(2 )
13- stack.append(3 )
14- stack.append(4 )
20+ >> > stack.append(0 )
21+ >> > stack.append(1 )
22+ >> > stack.append(2 )
1523
16- len (stack) # 4
24+ >> > len (stack)
25+ 3
1726
18- stack.pop() # 4
19- stack.pop() # 3
27+ >> > stack[0 ] # Bottom of the stack
28+ 0
29+ >> > stack[- 1 ] # Top of the stack
30+ 2
2031
21- len (stack) # 2
32+ >> > stack.pop()
33+ 2
34+ >> > stack.pop()
35+ 1
2236
23- stack.pop() # 2
24- stack.pop() # 1
37+ >> > len (stack)
38+ 1
2539
26- len (stack) # 0
40+ >> > stack.pop()
41+ 0
2742
28- stack.pop() # `IndexError: pop from empty list` since the `stack` list is empty
43+ >> > stack.pop() # `IndexError: pop from empty list`
44+ >> > stack[- 1 ] # `IndexError: pop from empty list`
2945```
3046
3147
3248## Queues
3349``` python
34- from collections import deque
35-
36- queue = deque()
50+ >> > from collections import deque
3751
38- queue.append(1 )
39- queue.append(2 )
40- queue.append(3 )
41- queue.append(4 )
52+ >> > queue = deque()
4253
43- len (queue) # 4
54+ # Enqueue -> append()
55+ >> > queue.append(0 )
56+ >> > queue.append(1 )
57+ >> > queue.append(2 )
4458
45- queue.popleft() # 1
46- queue.popleft() # 2
59+ >> > len (queue)
60+ 3
4761
48- len (queue) # 2
62+ >> > queue[0 ] # Head of the queue
63+ 0
64+ >> > queue[- 1 ] # Tail of the queue
65+ 2
4966
50- queue.popleft() # 3
51- queue.popleft() # 4
67+ # Dequeue -> popleft()
68+ >> > queue.popleft()
69+ 0
70+ >> > queue.popleft()
71+ 1
5272
53- len (queue) # 0
54-
55- queue.popleft() # `IndexError: pop from an empty deque` since the `queue` is empty
56- ```
73+ >> > len (queue)
74+ 2
5775
76+ >> > queue.popleft()
77+ 2
5878
59- ## Lists
79+ >> > len (queue)
80+ 0
6081
61- ## Strings
82+ >> > queue.popleft() # `IndexError: pop from an empty deque`
83+ >> > queue[0 ] # `IndexError: pop from an empty deque`
84+ ```
6285
63- ## Maps
6486
87+ ## Hash Tables
88+ TODO
6589
6690## Other
6791
68- ### Counter
69-
70-
71- https://wiki.python.org/moin/TimeComplexity
72- https://docs.python.org/3/library/collections.html
92+ ### collections
You can’t perform that action at this time.
0 commit comments