Isolation Centers - CORUS CodeChef May Long Challenge
Here is the link to the question.
Explanation:
We have to find the minimum size of pending queues. Given a string. For this we just need to do hashing. That’s it. After getting which type of virus attacked how many persons then, we can just subtract from C and add to pending queue list.
Here is the java code.
/* package codechef; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
Scanner s=new Scanner(System.in); //creating an object for Scanner class
int t=s.nextInt(); //reading number of testcases
while(t-->0)
{
int n=s.nextInt(); //reading length of the string
int q=s.nextInt(); //reading number of queries
String st=s.next(); // reading string
int []a=new int[26]; //creating an array of integers to store number of persons //attacked by respective virus.
for(int i=0;i<26;i++)
a[i]=0; //At first initialising all elements in array as 0
for(int i=0;i<n;i++)
{
int index=(st.charAt(i)-'a');
a[index]++; //incrementing count of persons attacked by //particular virus
}
for(int i=0;i<q;i++) //running through queries
{
long c=s.nextLong(); //reading the value of c
long x=0;
for(int j=0;j<26;j++)
{
if(a[j]>=c)
x=x+a[j]-c; //calculating minimum size of pending queues.
}
System.out.println(x);
}
s.close();
}
}
Comments
Post a Comment