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
data = [2,3,4,5,6] queries = [[2,3],[2,4],[4,10]] return = [21,21,27]
[2,3]=>[3,3,4,5,6]- 21[2,4]=>[3,3,4,5,6]- 21[4,10]=>[3,3,10,5,6]- 27
- Count Promotional PeriodsOA · Seen Jun 2026
- Find Maximum Total Amount (SDE I, Fungible :)Seen Jun 2026
- Get Minimum AmountOA · Seen Jun 2026
- Find Minimum CostOA · Seen Jun 2026
- Get Smallest Base SegmentOA · Seen Jun 2026
- Select Least Resource TasksOA · Seen Jun 2026
- Product Category Group SizesPHONE SCREEN · Seen May 2026
- Count Connected ComponentsPHONE SCREEN · Seen May 2026
public int[] getSumAfterQueries(int[] data, int[][] queries) {
// write your code here
}