FastPrepCount Values Appearing Exactly Once

Count Values Appearing Exactly Once

Agoda logoAgodaEasyFULLTIMEPHONE SCREEN
Learn

Problem statement

Given an integer array nums, return how many distinct values occur exactly once in the array.

A value contributes one to the answer only when its total frequency is one. Values that occur two or more times do not contribute.

Function

countAppearingOnce(nums: int[]) → int

Examples

Example 1

nums = [4,2,1,4,4,1,3]return = 2

Only 2 and 3 appear exactly once.

Example 2

nums = [7,7,7]return = 0

The only value occurs three times.

Example 3

nums = [-1,0,5]return = 3

Every value occurs once.

Constraints

  • 1 <= nums.length <= 10^5.
  • -10^9 <= nums[i] <= 10^9.

More Agoda problems

See Agoda hiring insights
public int countAppearingOnce(int[] nums) {
    // Write your solution here.
}
nums[4,2,1,4,4,1,3]
expected2
Checking account…