#Daily Coding Problem
def __init__(self, val, left=None, right=None):
self.val = val
self.left = left
self.right = right
2
1.5
2
3.5
2
2
2
input : 1 , Output : 1
input : 2 , Output : 0
input : 3 , Output : 0
input : 4 , Output : 0
input : 5 , Output : 1728 (it took 23 seconds)
[[1, 2, 3, 4, 5],
[6, 7, 8, 9, 10],
[11, 12, 13, 14, 15],
[16, 17, 18, 19, 20]]
1
2
3
4
5
10
15
20
19
18
17
16
11
6
7
8
9
14
13
12
(0, 0)
(1, 2)
(2, 2)
(4, 0)
[b 0 0 0 0]
[0 0 b 0 0]
[0 0 b 0 0]
[0 0 0 0 0]
[b 0 0 0 0]
ABACA
[ (0, 1),
(0, 2),
(2, 3),
(3, 4) ]
A
[ (0, 0) ]
1 | 2 | 3 | 4 | 5 | 6 |
2 | 4 | 6 | 8 | 10 | 12 |
3 | 6 | 9 | 12 | 15 | 18 |
4 | 8 | 12 | 16 | 20 | 24 |
5 | 10 | 15 | 20 | 25 | 30 |
6 | 12 | 18 | 24 | 30 | 36 |
cba daf ghi
ca df gi
abcdef
zyx wvu tsr
a
/ \
b c
/
d
a
/ \
b c
/ \ /
d e f
a
/ \
c b
\ / \
f e d
0 0 1 1 0
0 1 1 0 0
0 0 0 0 0
1 1 0 0 1
1 1 0 0 1
A N B
B NE C
C N A
A NW B
A N B
functions = []
for i in range(10):
functions.append(lambda : i)
for f in functions:
print(f())
{
'CSC300': ['CSC100', 'CSC200'],
'CSC200': ['CSC100'],
'CSC100': []
}
d.set(1, 1, 0) # set key 1 to value 1 at time 0
d.set(1, 2, 2) # set key 1 to value 2 at time 2
d.get(1, 1) # get key 1 at time 1 should be 1
d.get(1, 3) # get key 1 at time 3 should be 2
d.set(1, 1, 5) # set key 1 to value 1 at time 5
d.get(1, 0) # get key 1 at time 0 should be null
d.get(1, 10) # get key 1 at time 10 should be 1
d.set(1, 1, 0) # set key 1 to value 1 at time 0
d.set(1, 2, 0) # set key 1 to value 2 at time 0
d.get(1, 0) # get key 1 at time 0 should be 2
[
['A','B','C','E'],
['S','F','C','S'],
['A','D','E','E']
]
(x,y)
to
(x+1, y),
(x - 1, y),
(x, y+1),
(x, y-1),
(x-1, y-1),
(x+1,y+1),
(x-1,y+1),
(x+1,y-1)
1
/ \
2 3
/ \
4 5
1
/ \
2 3
/ \
4 5
0 3 1 1
2 0 0 4
1 5 3 1
Move 1 to 3
Move 1 to 2
Move 3 to 2
Move 1 to 3
Move 2 to 1
Move 2 to 3
Move 1 to 3
10
/ \
5 30
/ \
22 35
[[1, 0, 0, 0],
[1, 0, 1, 1],
[1, 0, 1, 1],
[0, 1, 0, 0]]
{
"top_left": (1, 4),
"dimensions": (3, 3) # width, height
}
and
{
"top_left": (0, 5),
"dimensions": (4, 3) # width, height
}
insert(key: str, value: int)
: Set a given key's value in the map. If the key already exists, overwrite the value. sum(prefix: str)
: Return the sum of all values of keys that begin with a given prefix.
mapsum.insert("columnar", 3)
assert mapsum.sum("col") == 3
mapsum.insert("column", 2)
assert mapsum.sum("col") == 5
graph = [
[0, 1, 3],
[1, 2],
[2],
[3]
]
[1, 1, 1, 1]
[0, 1, 1, 0]
[0, 0, 1, 0]
[0, 0, 0, 1]
1
/ \
2 3
/ \ / \
4 5 6 7
*
/ \
* *
/ \ / \
* a t *
/ \
c s
[('a', 1), ('a', 3), ('a', 5),
('b', 2), ('b', 6),
('c', 1), ('c', 2), ('c', 3), ('c', 4), ('c', 5)
('d', 4), ('d', 5), ('d', 6), ('d', 7),
('e', 1), ('e', 3), ('e': 5), ('e', 6)]
{ 'eat', 'rain', 'in', 'rat' }
and matrix:
[['e', 'a', 'n'],
['t', 't', 'i'],
['a', 'r', 'a']]
{
"word_1": ["meaning one", "meaning two", ...],
...
"word_n": ["meaning one", "meaning two", ...]
}
10
/ \
5 5
\ \
2 1
/
-1