#1655

Distribute Repeating Integers

master · 1695 · lc hard +32 · verified · 40.4% accepted · 470 likes · top 20%

Description

You have an array nums with at most 50 unique values and a quantity array for m customers. Each customer i must receive exactly quantity[i] copies of one value (all copies must be the same value). Determine whether it is possible to satisfy every customer. Return true if so, false otherwise.

Example 1:

Input: nums = [1,2,3,4], quantity = [2]
Output: false
Explanation: The 0th customer cannot be given two different integers.

Example 2:

Input: nums = [1,2,3,3], quantity = [2]
Output: true
Explanation: The 0th customer is given [3,3]. The integers [1,2] are not used.

Example 3:

Input: nums = [1,1,2,2], quantity = [2,2]
Output: true
Explanation: The 0th customer is given [1,1], and the 1st customer is given [2,2].

Code

1
2
3