# Leetcode’s Daily Challenge — 21/09/2022

**Problem** **—*** **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 print the sum of the even values of `nums`

.

Return *an integer array *`answer`

* where *`answer[i]`

* is the answer to the *`ith`

* query*.

**Solution —**

The approach is really simple. Traverse the entire nums array and store the sum of all even elements in a variable ** evenSum**.

Then traverse the queries array and for every query ** {val,idx},** check if

**current element i.e**

**is even or odd. If it’s even then first subtract**

*nums[idx]***from**

*nums[idx]***because we will be updating**

*evenSum***therefore we have to remove it from**

*nums[idx]***.**

*evenSum*Now update the value at ** nums[idx] i.e nums[idx] += val**.

Now check if the new value i.e ** nums[idx]** is even then add it to the

**i.e**

*evenSum***and push this value to the ans array.**

*evenSum += nums[idx],***C++ Code —** *Here*

**Analysis —**

Time Complexity— O(N+Q) //Linear

Space Complexity — O(Q) // To store the queries results into answer array

I hope the solution helps. Happy Coding!!!