Maximum Perimeter Triangle

  • + 0 comments

    Python best solution

    If you’re looking for solutions to the 3-month preparation kit in either Python or Rust, you can find them below: my solutions

        #Time complexity: O(n*log(n))
        #Space complexity (ignoring input): O(1)
        sticks.sort(reverse=True)
        for index in range(0, len(sticks) - 2):
            if sticks[index] < sticks[index + 1] + sticks[index + 2]:
                triangle = [sticks[index], sticks[index + 1], sticks[index + 2]]
                triangle.sort()
                return triangle
    
        return [-1]