Company: Oracle22aug
Difficulty: medium
Element Swapping Problem Description Given an array of n integers, you can perform the following operation any number of times: Choose any index i ( 0 ≤ i < n - 1 ) and swap arr[i] and arr[i + 1] . Each element can be swapped at most once during the process. The strength of an index i is defined as (arr[i] * (i + 1)) , using 0-based indexing. Find the maximum possible sum of the strength of all indices after optimal swaps. Complete the getMaximumSumOfStrengths function in the editor with the following parameters: int arr[n] : the initial array Returns: long int : the maximum possible sum of strengths of all indices after the operations are applied optimally. Examples Example 1: Input: n = 4, arr = [2,1,4,3] Output: 30 Explanation: Initial array: [2, 1, 4, 3] Optimal swaps: 1. Swap arr[2] and arr[3] . Array becomes [2, 1, 3, 4] . 2. Swap arr[0] and arr[1] . Array becomes [1, 2, 3, 4] . Final array: [1, 2, 3, 4] Sum of strengths = (1 * 1) + (2 * 2) + (3 * 3) + (4 * 4) = 1 + 4 + 9 +