• + 0 comments

    My idea is loop the array and plus earch number at index with K then push the result to Collections array. Next step I will check the element in Collections exist in arr and counting that.

    With c#

    public static int pairs(int k, List<int> arr)
        {
            var collections = arr.Select(number => k + number);
            var numberExisted = collections.Where(number => arr.Contains(number)).ToList();
            
            return numberExisted.Count();
        }