You are viewing a single comment's thread. Return to all comments →
Hi, can you help me what i am missing in below code as only 4 cases are failing.
using namespace std;
int max(int a,int b,int c) { int temp=0; if(a>b) { temp=a; } else { temp=b; } if(temp>c) { return temp; } else { return c; } }
// Complete the countTriplets function below. long countTriplets(int arr[], int r, int n) { map mp; for(int i=0;i
int m=mp.size(), res=0; if(r==1) { res=((mp[1])*(mp[1]-1)*(mp[1]-2))/(3*2); } else if(m>2) { for(int j=0;j<m-1;j++) { // cout<<mp[pow(r,j)]<<" "; if(mp[pow(r,j)] && mp[pow(r,j+1)] && mp[pow(r,j+2)]) { res=res+(mp[pow(r,j)]*mp[pow(r,j+1)]*mp[pow(r,j+2)]); } else { continue; } } } else { return 0; }
return res; }
int main() { int n,r; cin>>n; cin>>r; int a[n]; for(int i=0;i>a[i]; } long b=countTriplets(a,r,n); cout<
Also, can you share you code with proper explaintation.
Thanks in advance:)
Seems like cookies are disabled on this browser, please enable them to open this website
Count Triplets
You are viewing a single comment's thread. Return to all comments →
Hi, can you help me what i am missing in below code as only 4 cases are failing.
include
using namespace std;
int max(int a,int b,int c) { int temp=0; if(a>b) { temp=a; } else { temp=b; } if(temp>c) { return temp; } else { return c; } }
// Complete the countTriplets function below. long countTriplets(int arr[], int r, int n) { map mp; for(int i=0;i
return res; }
int main() { int n,r; cin>>n; cin>>r; int a[n]; for(int i=0;i>a[i]; } long b=countTriplets(a,r,n); cout<
Also, can you share you code with proper explaintation.
Thanks in advance:)