forked from dcprakash/codebase
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtips.yaml
More file actions
104 lines (80 loc) · 2.93 KB
/
tips.yaml
File metadata and controls
104 lines (80 loc) · 2.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
2-D:
helper row, col: helps to keep track of "count and location" of 1's in matrix
DFS/ BFS visited:
seen = set()
visited=[0]*N
visited=[[for j in range(n)] for i in range(n)]
flood-fill-algorithm
Good examples:
find-islands-maxarea
maximal_square
Array:
target sum: 4-subarray-sum-minimum-size, 4-subarray-with-given-sum
maintain sorted list: heapq (minimum-meeting_rooms)
queue to popleft: deque (findisland-rotting-oranges)
String:
ord(c) - to convert strint to integer
<number>*10 - to convert string to number (first digit is 0, then actual number)
Sliding Window:
https://github.com/dcprakash/codebase/blob/e9d45315727248ec53da54b24f4b54159f2cfe50/String/1-longest-substring-without-repeating-char-easy.py
loop and condition:
/HashTable/hashmap.py
https://www.tutorialspoint.com/python3/python_while_loop.htm
zip:
parallel iteration https://realpython.com/python-zip-function/
Python’s zip() function is defined as zip(*iterables).
The function takes in iterables as arguments and returns an iterator.
This iterator generates a series of tuples containing elements from each iterable.
zip() can accept any type of iterable, such as files, lists, tuples, dictionaries, sets, and so on.
numbers = [1, 2, 3]
letters = ['a', 'b']
zipped = zip(numbers, letters)
print(list(zipped))
# [(1, 'a'), (2, 'b')]
# output will be equal to the length of the shortest iterable.
# unzip along with the unpacking operator *
pairs = [(1, 'a'), (2, 'b'), (3, 'c'), (4, 'd')]
numbers, letters = zip(*pairs)
print(numbers)
# (1, 2, 3, 4)
print(letters)
# ('a', 'b', 'c', 'd')
sentinel nodes:
usage of temp nodes called sentinel
remove-linked-list-elements
list:
join:
list=[]
"".join(list)
".".join(list) # adds . inbetween each list item
deep copy:
nums=[1,3,5,6]
n=nums[:]
stack, queue:
queue=[]
queue.pop(0) # removes first item
queue.pop() # removes last item
queue.pop(-1) # removes last item
defaultdict:
Group-Anagrams
moving items in place:
Move-Zero-InPlace
filter and map:
valid-palindrome:
s="A man, a plan, a canal: Panama"
alnum=filter(lambda ch: ch.isalnum(), s)
slower=map(lambda ch: ch.lower(), alnum)
split:
path="root/a 1.txt(abcd) 2.txt(efgh)"
dir,*files=path.split(' ')
lambda:
find-smallest-divisor-given-threshold
top-k-frequent-words
dict:
trick1:
partition_labels:
s = "ababcbacadefegdehijhklij"
last = {c: i for i, c in enumerate(S)}
'a': 8, 'b': 5, 'c': 7, 'd': 14, 'e': 15, 'f': 11, 'g': 13, 'h': 19, 'i': 22, 'j': 23, 'k': 20, 'l': 21}
anchor reader writer:
string_compression