Class Solution
-
- All Implemented Interfaces:
public final class Solution3569 - Maximize Count of Distinct Primes After Split.
Hard
You are given an integer array
numshaving lengthnand a 2D integer arrayquerieswherequeries[i] = [idx, val].For each query:
Update
nums[idx] = val.Choose an integer
kwith1 <= k < nto split the array into the non-empty prefixnums[0..k-1]and suffixnums[k..n-1]such that the sum of the counts of distinct prime values in each part is maximum.
Note: The changes made to the array in one query persist into the next query.
Return an array containing the result for each query, in the order they are given.
Example 1:
Input: nums = 2,1,3,1,2, queries = [1,2,3,3]
Output: 3,4
Explanation:
Initially
nums = [2, 1, 3, 1, 2].After 1<sup>st</sup> query,
nums = [2, 2, 3, 1, 2]. Splitnumsinto[2]and[2, 3, 1, 2].[2]consists of 1 distinct prime and[2, 3, 1, 2]consists of 2 distinct primes. Hence, the answer for this query is1 + 2 = 3.After 2<sup>nd</sup> query,
nums = [2, 2, 3, 3, 2]. Splitnumsinto[2, 2, 3]and[3, 2]with an answer of2 + 2 = 4.The output is
[3, 4].
Example 2:
Input: nums = 2,1,4, queries = [0,1]
Output: 0
Explanation:
Initially
nums = [2, 1, 4].After 1<sup>st</sup> query,
nums = [1, 1, 4]. There are no prime numbers innums, hence the answer for this query is 0.The output is
[0].
Constraints:
<code>2 <= n == nums.length <= 5 * 10<sup>4</sup></code>
<code>1 <= queries.length <= 5 * 10<sup>4</sup></code>
<code>1 <= numsi<= 10<sup>5</sup></code>
0 <= queries[i][0] < nums.length<code>1 <= queries1<= 10<sup>5</sup></code>