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(sticks.size() < 3) return vector<int>{-1};
sort(sticks.begin(), sticks.end(), [](int m, int n){return m > n;});
int x = 0;
int y = 1;
int z = 2;
for(; sticks[y] + sticks[z] <= sticks[x]; x++,y++,z++) {
if(z >= sticks.size()) return vector<int>{-1};
}
return vector<int>{sticks[z], sticks[y], sticks[x]};
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 →
Just followed your Greedy idea :)