fork download
  1. import java.util.*;
  2. class Main{
  3. public static void main (String[] args) {
  4. Scanner sc=new Scanner(System.in);
  5. int [] arr1={5,4,6,6,7,7,3};
  6.  
  7. HashMap<Integer,Integer> map=new HashMap<>();
  8. for(int i=0;i<arr1.length;i++){
  9. map.put(arr1[i],map.getOrDefault(arr1[i],0)+1);
  10. }
  11. int max=0;
  12. for(int key:map.keySet()){
  13. if(map.get(key)>=max){
  14. max=map.get(key);
  15. }
  16. }
  17. System.out.println("No of operations required "+ (arr1.length-max));
  18. }
  19. }
Success #stdin #stdout 0.12s 56904KB
stdin
Standard input is empty
stdout
No of operations required 5