• + 0 comments
    function pairs(k, arr) {
        // Write your code here
        let map = arr.reduce((acc, id) => {
            acc.set(id, (acc.get(id) || 0) + 1);
            return acc;
        }, new Map());
        let count = 0;
        for(let [key, val] of map) {
            if(map.has(key-k)) count += val*map.get(key-k);
        }
        return count;
    }