Find Array obtained after adding terms of AP for Q queries | Function to find array after performing the given query to the array elements ; Traverse the given query ; Traverse the given array ; Update the value of A [ i ] ; Update the value of curr ; Print the array elements ; Driver Code ; Function Call
function addAP ( A , Q , operations ) { for ( let Q of operations ) { let L = Q [ 0 ] , R = Q [ 1 ] , a = Q [ 2 ] , d = Q [ 3 ] curr = a for ( let i = L - 1 ; i < R ; i ++ ) { A [ i ] += curr curr += d } } for ( let i of A ) { document . write ( i + " " ) } } let A = [ 5 , 4 , 2 , 8 ] let Q = 2 let Query = [ [ 1 , 2 , 1 , 3 ] , [ 1 , 4 , 4 , 1 ] ] addAP ( A , Q , Query )