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.
I came up with idea of moving forward and keeping a track of singles and doubles that have happened. This is passing all test cases except test case 6 :(
staticlongcountTriplets(List<long>arr,longr){Dictionary<long,long>singles=new();Dictionary<long,long>doubles=new();longcount=0;foreach(varnuminarr){longkeyByr=num/r;// If num completes a tripletif(doubles.ContainsKey(keyByr)){count+=doubles[keyByr];}// If num can be a middle of tripletif(singles.ContainsKey(keyByr)){if(doubles.ContainsKey(num))doubles[num]+=singles[keyByr];elsedoubles[num]=singles[keyByr];}// Count num as potential startif(singles.ContainsKey(num))singles[num]++;elsesingles[num]=1;}returncount;}
Cookie support is required to access HackerRank
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 →
Why is this failing hidden test case 6 :(
I came up with idea of moving forward and keeping a track of singles and doubles that have happened. This is passing all test cases except test case 6 :(