FastPrepDo All Frequencies Exceed a Threshold?

Do All Frequencies Exceed a Threshold?

Google logoGoogle● EasyNEW GRADPHONE SCREEN
Learn

Problem statement

Given an integer array nums and a nonnegative integer threshold, return true exactly when every distinct value in nums appears strictly more than threshold times.

An empty array returns true because it contains no value that violates the rule.

Function

allFrequenciesExceed(nums: int[], threshold: int) → boolean

Examples

Example 1

nums = [1,1,2,2]threshold = 1return = true

Both distinct values occur twice, which is strictly greater than 1.

Example 2

nums = [1,1,2]threshold = 1return = false

Value 2 occurs only once, so it does not exceed the threshold.

Example 3

nums = []threshold = 3return = true

No distinct value violates the requirement.

Constraints

  • 0 <= nums.length <= 200000.
  • -10^9 <= nums[i] <= 10^9.
  • 0 <= threshold <= nums.length.

More Google problems

See Google hiring insights
public boolean allFrequenciesExceed(int[] nums, int threshold) {
    // Write your code here.
}
nums[1,1,2,2]
threshold1
expectedtrue
Checking account…