Company: Google_5july
Difficulty: medium
Array function Problem Description You are given an array A of length N. A function F is defined as follows: F(A) = A[1] - A[2] + A[3] - A[4] + ... + (-1) (N+1) * A[N] You also have an array B having M pairs where an element is in the form [p, q] denoting that the elements of A at indices p and q are swappable. And you can swap these indices any number of times and in any order. Task Determine the maximum value of F(A) if you perform the swaps optimally. Note: 1-based indexing is used. Examples Example 1: Input: N = 4 A = [5, 6, 7, 8] M = 2 B = [[1, 2], [3, 4]] Output: 2 Explanation: The optimal approach will be to swap indices [1, 2] and [3, 4]. The array after that will be A = [6, 5, 8, 7]. So answer is F(A) = 6 - 5 + 8 - 7 = 2. Function description Complete the solve function provided in the editor. The function takes the following 4 parameters and returns the final value: N: Represents an integer denoting the number of elements in A A: Represents the array A M: Represents an intege