Distribute Repeating Integers

You are given an array of n integers, nums, where there are at most 50 unique values in the array. You are also given an array of m customer order quantities, quantity, where quantity[i] is the amount of integers the i^th customer ordered.

Determine if it is possible to distribute nums such that:

  • The i^th customer gets exactly quantity[i] integers.
  • The integers the i^th customer gets are all equal.
  • Every customer is satisfied.

Return true if it is possible to distribute nums according to the above conditions.

Example 1
Inputnums = [1,2,3,4], quantity = [2]
Outputfalse
The 0^th customer cannot be given two different integers.
Example 2
Inputnums = [1,2,3,3], quantity = [2]
Outputtrue
The 0^th customer is given [3,3], and the integers [1,2] are not used.

Constraints

  • n == nums.length
  • 1 <= n <= 10^5
  • 1 <= nums[i] <= 1000
  • m == quantity.length
  • 1 <= m <= 10
  • 1 <= quantity[i] <= 10^5
  • There are at most 50 unique values in nums.

Asked at 1 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate