Answer: FIBE (EARLY SALARY) Hiring Challenge | Off-Campus | OA (2024)
Answer · Posted Jun 2026
Approach Use a HashMap to store frequencies of previously seen numbers. For each number: Check how many times (num - k) appeared. Those occurrences form valid pairs. Add current number to the frequency map. This guarantees each pair is counted exactly once. Strategy One-pass traversal. Maintain frequency of visited elements. Count valid pairs on the fly. Java Code import java.util.HashMap; import java.util.Map; class Solution { public int countKDifference(int[] nums, int k) { Map<Integer, Integer> seen = new HashMap<>(); int count ...
The full answer & interview discussion are available to premium members.
Log in Create a free account