You are viewing a single comment's thread. Return to all comments →
What is about (2 3 3 9 15) input set? Here you get a triangle with 2 3 3 , but i also becomes -1. So output becomes -1; I had to add one extra check..
int i=n-3; while(i>=0 && arr[i]+arr[i+1]<=arr[i+2]) i--; if(i>0) printf("%d %d %d ",arr[i],arr[i+1],arr[i+2]); else if(arr[i]+arr[i+1]>arr[i+2]) printf("%d %d %d ",arr[i],arr[i+1],arr[i+2]); else printf("%d",-1);
Maximum Perimeter Triangle
You are viewing a single comment's thread. Return to all comments →
What is about (2 3 3 9 15) input set? Here you get a triangle with 2 3 3 , but i also becomes -1. So output becomes -1; I had to add one extra check..