Comments on: Number of possible triangles from given array of numbers https://demo.ritambhara.in/number-of-possible-triangles-from-given-array-of-numbers/ Coding / System Design Interviews Thu, 13 May 2021 13:09:45 +0000 hourly 1 https://wordpress.org/?v=6.7.2 By: Kalyanasundaram https://demo.ritambhara.in/number-of-possible-triangles-from-given-array-of-numbers/#comment-5637 Thu, 13 May 2021 13:09:45 +0000 http://www.ritambhara.in/?p=2324#comment-5637 Why sort?
Am I missing something? Kindly verify and correct me. Thanks

#include
int main()
{

int array[] = {10, 21, 22, 100, 101, 200, 300};

int size = sizeof(array)/sizeof(array[0]);
int start = 0, end = size-1;

int i = 0, count = 0;
int j = i+1;
int k = j+1;

while(i array[k])
{
printf(“{%d, %d, %d} “, array[i], array[j], array[k]);
count++;

if(k >= size-1)
{
i++;
j = i+1;
k = j+1;
}
else
{
j++;
k++;
}

}
else if(k >= size-1)
{
i++;
j = i+1;
k = j+1;
}
else
{
j++;
k++;
}
}
printf(“\nNumber of possible triangles can be formed from the array is: %d\n”, count);
return 0;
}

]]>
By: gIVA https://demo.ritambhara.in/number-of-possible-triangles-from-given-array-of-numbers/#comment-4358 Sun, 07 Jun 2020 13:51:44 +0000 http://www.ritambhara.in/?p=2324#comment-4358 Thanks, This really quick explanation saved a hell lot of time!

]]>
By: Shashank Mani Narayan https://demo.ritambhara.in/number-of-possible-triangles-from-given-array-of-numbers/#comment-1887 Wed, 12 Feb 2014 15:29:35 +0000 http://www.ritambhara.in/?p=2324#comment-1887 This is not correct , for input {10, 21, 22, 100, 101, 200, 300} no . of triangles should be 6 but your code will 5 , which is wrong.
{10, 21, 22}, {21, 100, 101}, {22, 100, 101}, {100, 101, 200} and {101, 200, 300} v {10, 100, 101}

]]>