You are viewing a single comment's thread. Return to all comments →
import java.util.*; public class Main { public static void main(String args[]) { Scanner sc= new Scanner(System.in); int n= sc.nextInt(); int[] arr= new int[n]; int count=0; for(int i=0;i<n;i++) { arr[i]=sc.nextInt(); } Arrays.sort(arr); int freq[]=new int[101]; for(int i=0;i<n;i++) { int a=arr[i]; freq[a]++; } for(int i=0;i<101;i++) { if(freq[i]>=1 || freq[i]%2==0) { count+=freq[i]/2; } else { freq[i]=freq[i]+1; count+=freq[i]/2; } } System.out.print(count); } }
Seems like cookies are disabled on this browser, please enable them to open this website
Sales by Match
You are viewing a single comment's thread. Return to all comments →