777. Maximum Good Subarray Length
Given two integer array nums and badNumbers, return the maximum length good subarray.
A subarray is good if it does not contain every number in badNumbers. All elements in badNumbers are distinct.
Example 1:
Input: nums = [2, 7, 3, 4, 5, 3], badNumbers = [7, 5]
Output: 4
Explanation: The optimal subarray is [3, 4, 5, 3], which does not contain all elements in badNumbers = [5, 7]
Example 2:
Input: nums = [8, 7, 3, 0, 2, 3, 6], badNumbers = [3, 7]
Output: 5
Explanation: The optimal subarray is [3, 0, 2, 3, 6], which does not contain all elements in badNumbers = [3, 7]
Still unsure what the problem is asking ?
Let’s go through a few more examples, step by step, to make it clearer.
Constraints:
- 1 <= nums.length <= 105
- 1 <= badNumbers.length <= 20
- -104 <= nums[i], badNumbers[i] <= 104
- all elements in badNumbers are distinct.