826. Maximum Consecutive Good Numbers

Given an array of integers nums and an array goodNumbers, return the maximum number of consecutive good numbers in the array.

Any number present in the goodNumbers array is a good number.

Example 1:

Input: nums = [1, 2, 3, 5, 4, 5, 1], goodNumbers = [3, 5]

Output: 2

Explanation:

[1, 2, 3, 5, 4, 5, 1] the underlined numbers are all good numbers and give the maximum length.

Example 2:

Input: nums = [4, 8, 1, 2, 0, 4, 6], goodNumbers = [1, 4, 2, 6]

Output: 2

Explanation:

[4, 8, 1, 2, 0, 4, 6] the underlined numbers are all good numbers and give the maximum length.

Note that the segment with index [5, 6] (0 - Based) was also a possible answer.

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 <= goodNumbers.length <= 105
  • -104 <= nums[i], goodNumbers[i] <= 104
0
class Solution {
public:
int maxConsecutiveGoodNums(vector<int>& nums, vector<int>& goodNumbers) {
 
}
};
Test Case

Input:

Good Numbers
Nums