We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
if tri[0] + tri[1] > tri[2] and tri[1] + tri[2] > tri[0] and tri[2] + tri[0] > tri[1]:
return True
return False
def maximumPerimeterTriangle(sticks):
n_tri = []
sticks.sort()
for i in range(len(sticks)):
tri = sticks[i:i + 3]
if len(tri) == 3 and valid_triangle(tri):
n_tri.append((tri, sum(tri)))
if len(n_tri) > 0:
m = max([i[1] for i in n_tri if i[1]])
n = max([i[0] for i in n_tri if i[1] >= m])
else:
n = [-1]
return n
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Maximum Perimeter Triangle
You are viewing a single comment's thread. Return to all comments →
def valid_triangle(tri):
def maximumPerimeterTriangle(sticks):