A data analyst recently joined HackerRank as an intern. As an initial task, data for n days is provided to the intern. Then, k updates are performed on the data, where each update is of the form [h,r]. This indicates that the subarray of data starting at index / and ending at index r is negated. For example, if data=[1,2,3, 4] and the updates are [2,4] then the data becomes data=[1,−2,−3,−4]. Given the initial data and k updates, find the final data after all updates. Note: 1-based indexing is used. Example Consider n=4, data =[1,−4,−5,2],k=2 and ypdates=[12,4],[1,2]). 1. After the first update, the data becomes data =[1,4,5,−2]. 2. After the second update, the data becomes data =[−7,−4,5,−2]. The final data is [−1,−4,5,−2]. Functlon Descriptlon Complete the function getFinalData in the editor below. getFinalData has the following parameters: int data[n] the initial data int updotes [k]2J, updates in the form of [h,d Returns int\{nj: the final data after all updates Constralnts - 1≤n≤105 - 1≤k≤105 - | datald ∣≤109 - Is updatestorojs updatesory] ≤n 1 > 'use strict'; - 26 27/∗ 28 * Complete the 'getFinalData' function below. 29 * * The function is expected to return an INTEGER_ARRAY. * The function accepts following parameters: * 1. INTEGER_ARRAY data * 2. 2D_INTEGER_ARRAY updates */ function getFinalData(data, updates) \{ I/ write your code here 41> function main() {−



Answer :

Other Questions