Intermediate Level
Implement the singleNumberTwoValuesCount method that counts the two values that appear once when others appear twice.
The input array nums contains integers where most values appear twice, but two values appear only once.
Your task is to return how many values appear exactly once. For the given problem pattern, the answer will be 2 when both single values are present.
For example, in [1,2,1,3,2,5], the values 3 and 5 appear once, so the answer is 2.
Count how many times each value appears.
Create a frequency map and increment the count for every number in the array. Then scan the frequency map and count how many values have frequency 1.
Return that count as the result.
Pseudocode:
function singleNumberTwoValuesCount(nums, size):
frequency = empty map
for i from 0 to size - 1:
frequency[nums[i]]++
count = 0
for each value in frequency:
if value == 1:
count++
return count