FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
interview/python/array/commonthreesortedarray.py at master · ankursd/interview · GitHub
ankursd
interview
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
interview
/
python
/
array
/
commonthreesortedarray.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
27 lines (24 loc) · 761 Bytes
Breadcrumbs
interview
/
python
/
array
/
commonthreesortedarray.py
Copy path
File metadata and controls
27 lines (24 loc) · 761 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
# http://www.geeksforgeeks.org/find-common-elements-three-sorted-arrays/
def
common_elements
(
input1
,
input2
,
input3
):
result
=
[]
i
=
0
j
=
0
k
=
0
while
i
<
len
(
input1
)
and
j
<
len
(
input2
)
and
k
<
len
(
input3
):
if
input1
[
i
]
==
input2
[
j
]
and
input2
[
j
]
==
input3
[
k
]:
result
.
append
(
input1
[
i
])
i
=
i
+
1
j
=
j
+
1
k
=
k
+
1
elif
input1
[
i
]
<
input2
[
j
]:
i
=
i
+
1
elif
input2
[
j
]
<
input3
[
k
]:
j
=
j
+
1
else
:
k
=
k
+
1
return
result
if
__name__
==
'__main__'
:
input1
=
[
1
,
5
,
10
,
20
,
40
,
80
]
input2
=
[
6
,
7
,
20
,
80
,
100
]
input3
=
[
3
,
4
,
15
,
20
,
30
,
70
,
80
,
120
]
print
(
common_elements
(
input1
,
input2
,
input3
))
Back
|
FazBrowse Home
|
New Git URL