Description
Solutions
Number of Unique Elements After Modifications 🍁
📚RELATED PROBLEMS
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:
- Update
A[L-1] = A[L-1] - x
whereL
isqueries[i][0]
value of query andx
isqueries[i][1]
value of each indexi
. - Copy the modified array in
B
such thatA[0] = B[0]
andB[i] = min(B[i-1], A[i])
for1 <= i < n
.
Your result should be the unique number of elements in B
after every operation.
res[i]
denotes the result after i
th operation.
Return the result array after performing all the operations.
Example 1:
Input: nums = [5, 7, 2, 2, 4], queries = [[3, 5], [5, 4]]
Output: [2, 3]
Explanation:After the first operation,A
is5 5 2 2 4
then copy it toB
as per the rule then we getB
as5 5 2 2 2
so the result after the 1st operation is2
. After the 2nd operation,A
becomes5 5 2 2 0
then we getB
as5 5 2 2 0
so the result after the 2nd operation is3
. Then the final result is{2,3}
.
Constraints:
1 <= n <= 1e5
1 <= m <= 1e5
1 <= A[i] <= 1e9
1 <= Q[i][j] <= 1e5

Related Problems
Testcase
Result
Case 1
input:
output: