Company: Deshaw full time_15march
Difficulty: medium
You are given an array of integers arr[] of length n . In one operation, you can do the following: Choose an element, and move it to the end of the array without changing the order of the other elements. Your goal is to perform the minimum number of operations such that all equal elements are grouped together. Note: A grouping is successful if, for every value x in the array, all occurrences of x appear in one single contiguous block. Example n = 5 arr = [1, 2, 2, 1, 3] In this case, the array is [1, 2, 2, 1, 3]. One way to group equal elements is: Move the element at position 4 to the end → [1, 2, 2, 3, 1] Move the element at position 1 to the end → [2, 2, 3, 1, 1] Now, all 1s, 2s, and 3s are grouped together. Hence, the answer is 2. Function Description Complete the function getMinOperations in the editor below. getMinOperations has the following parameter: int arr[n] : the elements of the array arr . Returns int : an integer denoting the minimum number of operations needed