Company: Twilio
Difficulty: medium
Twilio Segment Optimality Quotient Twilio segment is all about dealing with data, sending data from multiple sources to multiple destinations. Given an array of sources arr, we can rearrange it to form the destination array, let\'s call it rearranged_arr . Now while rearranging we want to transfer the data in the most optimal way possible. Optimality quotient is measured by the greatness of the array multiplied by 2. The greatness of the array is defined as the number of indices i, 0 ≤ i rearranged_arr[i] > arr[i] . That is, the element placed after rearrangement is greater than the initial value present at that index. Given the initial array arr, find the optimality quotient of the array. Input Format The first line contains an integer, n, the number of elements in arr. Each line i of the n subsequent lines (where 0 ≤ i Constraints 1 ≤ n ≤ 10 5 1 ≤ arr[i] ≤ 10 9 Example 1 Input: arr = [1, 3, 5, 2, 1, 3, 1] Output: 8 [1, 3, 5, 2, 1, 3, 1] → original arr [2, 5, 1, 3, 3, 1, 1] → optimal