Description
Solutions
Submission
Get Final Data

As an initial task, data for n days is provided to the intern. Thenkupdates are performed on the data, where each update is of the form [l, r]. This indicates that the subarray of data starting at index l and ending at index r is negated. For example, if data = [1, 2, 3, 4] and the udpates are [2, 4] then the data becomes data = [1, -2, -3, -4].

Given the initial data and kupdates, find the data after all updates.

Note:

1-based indexing is used.

Function Description

Complete the function getFinalData in the editor.

getFinalData has the following parameter(s):

  • int[] data: the initial data
  • int[k][2]: updates in the form of [l, r]
  • Returns

  • int[]: the final data after all udpates
  • Example 1:

    Input:  data = [1, -4, -5, 2], updates = [[2, 4], [1, 2]]
    Output: [-1, -4, 5, -2]
    Explanation:
    Consider n = 4, data = [1, -4, -5, 2], k = 2 and updates = [[2, 4], [1, 2]]. 1. After the fist update, the data becomes data = [1, 4, 5, -2]. 2. After the second update, the data becomes data = [-1, -4, 5, -2]. The final data is [-1, -4, 5, -2].
    Constraints:
    • 1 <= n <= 105
    • 1 <= k <= 105
    • |data[i]| <= 109
    • 1 <= updates[i][0] <= updates[i][1] <= n
    Testcase

    Result
    Case 1

    input:

    output: