Calculate the Sum
There is a row of two-position switches aligned in a row and numbered consecutively starting from 1. Each of the switches is initially in its "Off" position. Over some number of operations, a left and right index will be provided. When a current is applied to two switches, a NOT operation is applied to each switch in the inclusive interval between those switches. That is, if a switch is off, it is turned on, and vice versa. Given a series of operations, determine their final state. Calculate the sum of all indices where a switch is on.
Complete the function calculateTheSum in the editor.
calculateTheSum has the following parameter:
int n: the number of operationsint[][] operations: a 2D array of integers where each element is an array of two integers representing the left and right indices for the operation
Returns
int: the sum of all indices where a switch is on
🌷ଓ Credit to Charlotte༉˚
1Example 1

Constraints
Limits and guarantees your solution can rely on.
(˶˃ ᵕ ˂˶) .ᐟ.ᐟ