FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
interview/python/array/numberoftrianglesunsortedarray.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
/
numberoftrianglesunsortedarray.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
20 lines (14 loc) · 492 Bytes
Breadcrumbs
interview
/
python
/
array
/
numberoftrianglesunsortedarray.py
Copy path
File metadata and controls
20 lines (14 loc) · 492 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
# http://www.geeksforgeeks.org/find-number-of-triangles-possible/
def
number_of_triangles
(
input
):
input
.
sort
()
count
=
0
for
i
in
range
(
len
(
input
)
-
2
):
k
=
i
+
2
for
j
in
range
(
i
+
1
,
len
(
input
)):
while
k
<
len
(
input
)
and
input
[
i
]
+
input
[
j
]
>
input
[
k
]:
k
=
k
+
1
count
+=
k
-
j
-
1
return
count
if
__name__
==
'__main__'
:
input
=
[
15
,
9
,
8
,
3
,
4
,
5
,
6
]
print
(
number_of_triangles
(
input
))
Back
|
FazBrowse Home
|
New Git URL