FastPrepFastPrep
Problem Brief

Number of Unique Elements After Modifications 🍁

OA

You are given an array of nums of size n and queries of size m. For each queries you need to perform the following operation:

  1. Update A[L-1] = A[L-1] - x where L is queries[i][0] value of query and x is queries[i][1] value of each index i.
  2. Copy the modified array in B such that A[0] = B[0] and B[i] = min(B[i-1], A[i]) for 1 <= i < n.

Your result should be the unique number of elements in B after every operation. res[i] denotes the result after ith operation. Return the result array after performing all the operations.

1Example 1

Input
nums = [5, 7, 2, 2, 4], queries = [[3, 5], [5, 4]]
Output
[2, 3]
Explanation
After the first operation, A is 5 5 2 2 4 then copy it to B as per the rule then we get B as 5 5 2 2 2 so the result after the 1st operation is 2. After the 2nd operation, A becomes 5 5 2 2 0 then we get B as 5 5 2 2 0 so the result after the 2nd operation is 3. Then the final result is {2,3}.

Constraints

Limits and guarantees your solution can rely on.

  • 1 <= n <= 1e5
  • 1 <= m <= 1e5
  • 1 <= A[i] <= 1e9
  • 1 <= Q[i][j] <= 1e5
  • public int[] getUniqueElementCounts(int[] nums, int[][] queries) {
        // write your code here
    }
    
    Input

    nums

    [5, 7, 2, 2, 4]

    queries

    [[3, 5], [5, 4]]

    Output

    [2, 3]

    Sign in to submit your solution.