-
Notifications
You must be signed in to change notification settings - Fork 0
/
Interview.py
153 lines (109 loc) · 3.26 KB
/
Interview.py
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<<<<<<< HEAD
# Python interview
arr1=[2,4,5,7,9,11,12,15,17]
arr2=[1,2,4,6]
################################
# merge two sorted arrays
def sortedArrayMerge(arr1,arr2):
res=[]
while (arr1 and arr2):
if (arr1[0] < arr2[0]):
if res and arr1[0] == res[-1]:
arr1.pop(0)
continue
res.append(arr1.pop(0))
else:
if res and arr2[0] == res[-1]:
arr2.pop(0)
res.append(arr2.pop(0))
if (arr1 > arr2):
res.extend(arr1)
else:
res.extend(arr2)
print (res )
sortedArrayMerge(arr1,arr2)
pass
#Matrix: look for the zero-nodes and then replace by 0 the values in same column and row
Matrix=[
[2,3,5,1,6],
[0,3,5,1,6],
[2,3,5,1,0],
]
def printMatrix(*args):
for i in args:
print (i)
def cross_zero(a,b,Matrix):
pass
for i in range(len(Matrix)):
for j in range(len(Matrix[i])):
#if i==node[0] or j==node[1]:
if i==a or j==b:
Matrix[i][j]=0
found=[]
for i in range(len(Matrix)):
if any (i in node for node in found):
Matrix[i][j]=0
for j in range(len(Matrix[i])):
#print (Matrix[i][j])
if Matrix[i][j]==0:
found.append((i,j))
elif any (i in node for node in found) or any (j in node for node in found): #if any('apple' in code for code in CODES):
Matrix[i][j]=0
for a in [ b in cross_zero(i,j,Matrix) for i,j in found]:
print (a)
printMatrix(*Matrix)
=======
# Python interview
arr1=[2,4,5,7,9,11,12,15,17]
arr2=[1,2,4,6]
################################
# merge two sorted arrays
def sortedArrayMerge(arr1,arr2):
res=[]
while (arr1 and arr2):
if (arr1[0] < arr2[0]):
if res and arr1[0] == res[-1]:
arr1.pop(0)
continue
res.append(arr1.pop(0))
else:
if res and arr2[0] == res[-1]:
arr2.pop(0)
res.append(arr2.pop(0))
if (arr1 > arr2):
res.extend(arr1)
else:
res.extend(arr2)
print (res )
sortedArrayMerge(arr1,arr2)
pass
#Matrix: look for the zero-nodes and then replace by 0 the values in same column and row
Matrix=[
[2,3,5,1,6],
[0,3,5,1,6],
[2,3,5,1,0],
]
def printMatrix(*args):
for i in args:
print (i)
def cross_zero(a,b,Matrix):
pass
for i in range(len(Matrix)):
for j in range(len(Matrix[i])):
#if i==node[0] or j==node[1]:
if i==a or j==b:
Matrix[i][j]=0
found=[]
for i in range(len(Matrix)):
if any (i in node for node in found):
Matrix[i][j]=0
for j in range(len(Matrix[i])):
#print (Matrix[i][j])
if Matrix[i][j]==0:
found.append((i,j))
elif any (i in node for node in found) or any (j in node for node in found): #if any('apple' in code for code in CODES):
Matrix[i][j]=0
for a in [ b in cross_zero(i,j,Matrix) for i,j in found]:
print (a)
printMatrix(*Matrix)
>>>>>>> e55f97114d0da06a25cf60393f67b0e16521bd92