Count Prime-Gap Balanced Subarrays - Practice Coding | SlaveCode
0
0123456789
0
0123456789
:
0
0123456789
0
0123456789
3589. Count Prime-Gap Balanced Subarrays
Medium
30 Points
Array
Math
Queue
Sliding Window
Number Theory
Monotonic Queue
You are given an integer array nums and an integer k.
A subarray is called prime-gap balanced if:
Return the count of prime-gap balanced subarrays in nums.
Note:
Examples
Example 1
Input: nums = [1,2,3], k = 1
Output: 2
Explanation:
Prime-gap balanced subarrays are:
Thus, the answer is 2.
Example 2
Input: nums = [2,3,5,7], k = 3
Output: 4
Explanation:
Prime-gap balanced subarrays are:
Thus, the answer is 4.
Constraints
1 <= nums.length <= 5 * 104
1 <= nums[i] <= 5 * 104
0 <= k <= 5 * 104
3589. Count Prime-Gap Balanced Subarrays
Medium
30 Points
Array
Math
Queue
Sliding Window
Number Theory
Monotonic Queue
You are given an integer array nums and an integer k.
A subarray is called prime-gap balanced if:
Return the count of prime-gap balanced subarrays in nums.
Note:
Examples
Example 1
Input: nums = [1,2,3], k = 1
Output: 2
Explanation:
Prime-gap balanced subarrays are:
Thus, the answer is 2.
Example 2
Input: nums = [2,3,5,7], k = 3
Output: 4
Explanation:
Prime-gap balanced subarrays are:
Thus, the answer is 4.