We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
importjava.io.*;importjava.util.*;importjava.text.*;importjava.math.*;importjava.util.regex.*;publicclassSolution{publicstaticvoidmain(String[]args){/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */Scannersc=newScanner(System.in);intn=sc.nextInt();int[]a=newint[n];for(inti=0;i<n;i++){a[i]=sc.nextInt();}Arrays.sort(a);intcost=1;intp=a[0];for(inti=0;i<n;i++){if(a[i]>p+4){cost=cost+1;p=a[i];}}System.out.println(cost);}}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Priyanka and Toys
You are viewing a single comment's thread. Return to all comments →