Distribute Repeating Integers - Problem
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.
Input & Output
Example 1 — Basic Distribution
$
Input:
nums = [1,2,3,4], quantity = [2]
›
Output:
false
💡 Note:
No single value appears twice. Customer wants 2 identical items but max frequency is 1.
Example 2 — Successful Distribution
$
Input:
nums = [1,2,3,3], quantity = [2]
›
Output:
true
💡 Note:
Value 3 appears twice. Customer gets [3,3] which satisfies quantity = 2.
Example 3 — Multiple Customers
$
Input:
nums = [1,1,2,2], quantity = [2,2]
›
Output:
true
💡 Note:
Customer 0 gets [1,1], Customer 1 gets [2,2]. Both satisfied with identical items.
Constraints
- n == nums.length
- 1 ≤ n ≤ 105
- 1 ≤ nums[i] ≤ 1000
- m == quantity.length
- 1 ≤ m ≤ 10
- 1 ≤ quantity[i] ≤ 105
- There are at most 50 unique values in nums.
Visualization
Tap to expand
Understanding the Visualization
1
Input Analysis
Count frequency of each unique number in the array
2
Assignment Process
Try to assign item types to customers based on their quantity needs
3
Validation
Check if all customers can be satisfied with identical items
Key Takeaway
🎯 Key Insight: Group identical items by frequency, then use backtracking or bitmask DP to find valid customer assignments
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code