You are viewing a single comment's thread. Return to all comments →
Here is my O(n) c++ solution, you can watch the implementation here : https://youtu.be/vLD3N79nLSE
int beautifulTriplets(int d, vector<int> arr) { map<int, int> mp; int result = 0; for (int a : arr) { mp[a] += 1; result += mp[a-d]*mp[a-2*d]; } return result; }
Seems like cookies are disabled on this browser, please enable them to open this website
Beautiful Triplets
You are viewing a single comment's thread. Return to all comments →
Here is my O(n) c++ solution, you can watch the implementation here : https://youtu.be/vLD3N79nLSE