Maximum Perimeter Triangle

  • + 0 comments

    Here is my c++ solution, you can watch the explanation here : https://youtu.be/cP4PLTgC1OE

    vector<int> maximumPerimeterTriangle(vector<int> sticks) {
        sort(sticks.begin(), sticks.end());
        for(int i = sticks.size() - 1; i >= 2; i--){
            if(sticks[i] < sticks[i - 1] + sticks[i - 2]) return {sticks[i - 2], sticks[i -1], sticks[i] };
        }
        return {-1};
    }