Mid/SeniorArraySimulation

Sum of Even Numbers After Queries

You are given an integer array nums and an array queries where queries[i] = [vali, indexi].

For each query i:

  • First, apply nums[indexi] = nums[indexi] + vali.
  • Then compute the sum of the even values of nums.

Return an integer array answer where answer[i] is the answer to the i^th query.

Example 1
Inputnums = [1,2,3,4], queries = [[1,0],[-3,1],[-4,0],[2,3]]
Output[8,6,2,4]
Starting from [1, 2, 3, 4], the even sums after each update are 8, 6, 2, and 4.
Example 2
Inputnums = [1], queries = [[4,0]]
Output[0]
After adding 4 to nums[0], the array becomes [5], which has no even values, so the sum is 0.

Constraints

  • 1 <= nums.length <= 10^4
  • -10^4 <= nums[i] <= 10^4
  • 1 <= queries.length <= 10^4
  • -10^4 <= vali <= 10^4
  • 0 <= indexi < nums.length

Asked at 1 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate