This function assumes that a [ ] is sorted . If a [ ] is not sorted , we need to sort it first .
import java . io . * ; import java . util . * ; class GFG { public static int minCostToMakeElementEqual ( int a [ ] , int n ) {