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.
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int k=in.nextInt();
int count=0;
int a[]=new int[n];
for(int i=0; i < n; i++){
a[i] = in.nextInt();
}
int b[]=new int[k+1];
for(int i=0;i<n;i++)
{
b[a[i]%k]=b[a[i]%k]+1;
}
int cond=(k%2==0)?k/2:(k/2)+1;
for(int j=0;j<cond;j++)
{
if(b[0]!=0&&j==0)
count++;
else
count+=(b[j]>b[k-j])?b[j]:b[k-j];
}
if(k%2==0)
count+=1;
System.out.println(count);
in.close();
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Non-Divisible Subset
You are viewing a single comment's thread. Return to all comments →
Thought to share my code in java :
in.close(); }