Grokking the Engineering Manager Coding Interview
Ask Author
Back to course home

0% completed

Vote For New Content
Ionut Enescu
1 loop solution

Ionut Enescu

Jan 9, 2025

    public int countElements(int[] arr) {         int count = 0;         Set<Integer> mySet = new HashSet<>();         for (int i = 0; i < arr.length; i++) {             mySet.add(arr[i]);             if (mySet.contains(arr[i] + 1) || mySet.contains(arr[i] - 1)) {                 count++;             }         }         return count;     }

0

0

Comments
Comments