• + 0 comments

    function beautifulTriplets(d, arr) {

    let hash = {}
    let counter = 0
    for (const n of arr) {
        hash[n] = !hash[n] ? 1 : hash[n] + 1;
    }
    
    for (const k in hash) {
        const sec = Number(k) + d;
        const third = sec + d;
    
        if (hash[sec] && hash[third]) counter += Math.max(hash[k], hash[sec], hash[third])
    }
    return counter
    

    }