You are viewing a single comment's thread. Return to all comments →
#include<iostream> #include<algorithm> using namespace std; int main() { int n; cin>>n; int a[n]; for(int i=0;i<n;i++) cin>>a[i]; int b=0; int total=0; sort(a,a+n); b=a[0]; for(int i=1;i<n;i++) { if(a[i]-b>4) { total++; b=a[i]; } } cout<<total+1; }
This is a pretty short code passing all the test cases.
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 →
This is a pretty short code passing all the test cases.