Company: Google_5july
Difficulty: medium
Sort the Array Problem Description You are given an integer array A of size N in which every element is 1 , 2 or 3 . You are also given Q queries. The i -th query is a pair queries[i][0] , queries[i][1] . To process it you must: Set A[queries[i][0]] = queries[i][1] . Report the minimum number of swaps needed to rearrange the current contents of A into non-decreasing order. A swap exchanges the elements at any two positions of the array. The two positions do not have to be adjacent. (inferred - the source never says which swaps are allowed; its own worked example exchanges positions 0 and 3, which are not adjacent, so arbitrary pairs are permitted.) Reporting the answer does not sort the array. The array is only ever changed by the assignment in step 1, and those assignments accumulate: query i acts on the array left behind by query i - 1 . Task For each query, print the minimum number of swaps required to sort the array in non-decreasing order at that moment. Input Format The first lin