Answer: ZETA SUITE Hiring Off-Campus OA (2024) | Problem Number of Good Pairs
Answer · Posted Jun 2026
Approach Use a frequency map. While traversing the array: If a number has appeared k times before, then the current occurrence forms k new good pairs. Add k to the answer. Increment the frequency of the current number. Strategy Create a HashMap to store frequencies. Traverse the array. Add existing frequency to the result. Update frequency. This counts all valid pairs in a single pass. Java Solution: import java.util.HashMap; import java.util.Map; class Solution { public int numIdenticalPairs(int[] nums) { Map<Integer, ...
The full answer & interview discussion are available to premium members.
Log in Create a free account