FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python_practice/hackerrankcombination.py at master · danglingmind/python_practice · GitHub
danglingmind
python_practice
Repository navigation
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
python_practice
/
hackerrankcombination.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
22 lines (18 loc) · 564 Bytes
Breadcrumbs
python_practice
/
hackerrankcombination.py
Copy path
File metadata and controls
22 lines (18 loc) · 564 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
#!/bin/python3
from
itertools
import
combinations
def
totalTriplets
(
capacity
,
desiredCapacity
):
l
=
len
(
capacity
)
count
=
0
ind
=
[]
for
i
in
range
(
l
):
ind
.
append
(
i
)
# get the combinations of indexes
indexcombi
=
combinations
(
ind
,
3
)
for
j
in
indexcombi
:
if
(
j
[
0
]
+
1
==
j
[
1
]
or
j
[
1
]
+
1
==
j
[
2
]):
if
capacity
[
j
[
0
]]
*
capacity
[
j
[
1
]]
*
capacity
[
j
[
2
]]
==
desiredCapacity
:
count
+=
1
return
count
if
__name__
==
'__main__'
:
result
=
totalTriplets
([
1
,
2
,
2
,
2
,
4
],
8
)
print
(
result
)
Back
|
FazBrowse Home
|
New Git URL