Sum After Query Update
Hello! I feel like it's a duplicate of another existing problem..but I couldnt find it. If you happen to know the duplicate, please let me know. Manyyyy thanks in advance. You are the best!
There are data points as integer array and array of queries. Where each query is: q[i][0] = old value, q[i][1] = new value. After processing i-th query you need to update all data points having value 'old value' to 'new value' and calculate total sum of all data points.
Return array of sums after each query executed.
Watch out for special cases like duplicates and zero updates (same value or value doesn't exist in the current array).
Complete the function getSumAfterQueries in the editor.
getSumAfterQueries has the following parameters:
- 1.
int[] data: an array of integers representing the data points - 2.
int[][] queries: an array of queries wherequeries[i][0]is the old value andqueries[i][1]is the new value
Returns
int[]: an array of integers representing the sum of data points after each query
1Example 1
[2,3]=>[3,3,4,5,6]- 21[2,4]=>[3,3,4,5,6]- 21[4,10]=>[3,3,10,5,6]- 27