Company: Uber_14july
Difficulty: medium
Count Swaps During Custom Sorting Problem Description Analyze the efficiency of the following sorting algorithm by counting the number of swaps it performs: For an array arr of size n : Find the smallest pair of indices 0 ≤ i < j ≤ n-1 such that arr[i] > arr[j] . "Smallest" means lexicographical ordering of pairs (i, j) (i.e., smallest i , then smallest j for that i ). If no such pair exists, the algorithm stops. Otherwise, swap arr[i] and arr[j] and search for the next pair. Your task is to determine how many swaps this algorithm performs to sort a given array. Function Description Complete the function howManySwaps in the editor with the following parameter(s): int arr[n] : the array to sort Returns long : the number of swaps Examples Example 1: Input: n = 4, arr = [5, 1, 4, 2] Output: 4 Explanation: The algorithm performs these swaps: [5, 1, 4, 2] -> [1, 5, 4, 2] (swap indices 0 and 1) [1, 5, 4, 2] -> [1, 4, 5, 2] (swap indices 1 and 2) [1, 4, 5, 2] -> [1, 4, 2, 5] (swap