Distribute Repeating Integers
Hard · Array, Dynamic Programming, Backtracking, Bit Manipulation, Bitmask
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 ith customer ordered. Determine if it is possible to distribute nums such that:
Return true if it is possible to distribute nums according to the above conditions.
Example 1
Input: nums = [1,2,3,4], quantity = [2] Output: false
The 0th customer cannot be given two different integers.
Example 2
Input: nums = [1,2,3,3], quantity = [2] Output: true
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
The 0th customer is given [1,1], and the 1st customer is given [2,2].
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.
Starter code (python)
class Solution(object):
def canDistribute(self, nums, quantity):
"""
:type nums: List[int]
:type quantity: List[int]
:rtype: bool
"""
Related problems
- Two Sum (Easy)
- Median of Two Sorted Arrays (Hard)
- Longest Palindromic Substring (Medium)
Previous: Slowest Key · Next: Check Array Formation Through Concatenation · All problems
Zepruv is a technical interview practice platform. Read any problem for free; sign in to run your code, submit and keep your progress.