Beautiful Triplets | hackerrank Solution in C++
Beautiful Triplets | hackerrank Solution
It is an hackerrank problem you can find it by clicking here.
Below given solution is prepared by one of the coder of our.
Soultion in C++
#include<iostream>
using namespace std;
int main()
{
int n,d,count=0;
cin>>n>>d;
int *arr;
arr = new int [n];
for(int i=0;i<n;i++)
{
cin>>arr[i];
for(int j=0;j<i;j++)
{
if((arr[i]-arr[j])==d)
{
for(int l=0;l<j;l++)
{
if((arr[j]-arr[l])==d)
count++;
}
}
}
}
cout<<count;
return 0;
}

Comments
Post a Comment