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.
#Python using a hash map. O(N) time and space complexity defbeautifulTriplets(d,arr):arr_map={}forninarr:arr_map[n]=arr_map.get(n,0)+1count=0forninarr_map.keys():ifn+dinarr_mapand(n+2*d)inarr_map:count+=arr_map[n]*arr_map[n+d]*arr_map[n+2*d]returncount
Cookie support is required to access HackerRank
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 →