The City of Wonderland is under attack by an unknown virus. There are twenty six types of people who reside in the city of Wonderland i.e every person in the city belongs to any one of the types from a - z.
Many people have got infected by the virus and are fighting for their lives. Scientists have studied the virus and its impact on different types of people. After their study, they found that the virus is unable to cause damage to any of the people who belong to the type which are maximum in the city.
For example - If in the city, the maximum people belong to the type b, then all b types of people will be safe from the virus.
Scientists want to know the type for which the people are maximum so that they can safeguard them and also develop vaccination as an antidote to the virus which will provide immunity to other people. They are short of time and therefore need your help in determining the type for which the people are maximum in the city.
Note: If there are more than one type of people with equal maximum then the type with lesser ASCII value will be considered.
Can you help the Scientists in saving the city ?
Input Format
The first line of input consists of number of test cases, T.
The second line of each test case consists of a string representing the type of each individual person in the city.
Constraints
1<= T <=10
1<= |string| <=100000
Output Format
For each test case, print the required output in a separate line.
Sample TestCase 1
Input
2
gqtrawq
fnaxtyyzz
Output
q
y
Explanation
Test Case 1: There are 2 q types of people rest all are present alone.
Test Case 2: There are 2 y and 2 z types of people. Since the maximum value is same, the type with lesser Ascii value is considered as output. Therfore, y is the correct type.
Time Limit(X):
0.50 sec(s) for each input.
Memory Limit:
512 MB
Source Limit:
100 KB
It is working without errors in my local IDE and also working on ideone, please provide me the link of the question so i can investigate further
Note: I’m using python 3.6
Can you help me in solving this puzzle.
Today is the last day my one test case is only passed but rest are failing.
I am sharing my code in java:
import java.io.;
import java.util.;
public class CandidateCode {
public static void main(String args[] ) throws Exception {
//Write code here
//Write code here
Scanner in = new Scanner(System.in);
int a;
a = in.nextInt();
String s2;
String s3;
for(int i=0;i<=a;i++){
// in.nextLine();
s2 = in.nextLine();
char[] arr = s2.toCharArray();
System.out.println(firstRepeating(arr));
}
}
static char firstRepeating(char str[])
{
// Creates an empty hashset
HashSet h = new HashSet<>();
// Traverse the input array from left to right
for (int i=0; i<=str.length-1; i++)
{
char c = str[i];
// If element is already in hash set, update x
// and then break
if (h.contains(c))
return c;
else // Else add element to hash set
h.add(c);
}
return '\0';
}
The City of Wonderland is under attack by an unknown virus. There are twenty six types of people who reside in the city of Wonderland i.e every person in the city belongs to any one of the types from a - z.
Many people have got infected by the virus and are fighting for their lives. Scientists have studied the virus and its impact on different types of people. After their study, they found that the virus is unable to cause damage to any of the people who belong to the type which are maximum in the city.
For example - If in the city, the maximum people belong to the type b, then all b types of people will be safe from the virus.
Scientists want to know the type for which the people are maximum so that they can safeguard them and also develop vaccination as an antidote to the virus which will provide immunity to other people. They are short of time and therefore need your help in determining the type for which the people are maximum in the city.
Note: If there are more than one type of people with equal maximum then the type with lesser ASCII value will be considered.
Can you help the Scientists in saving the city ?
Input Format
The first line of input consists of the number of test cases, T.
Next T lines each consists of a string representing the type of each individual person in the city.
Constraints
1<= T <=10
1<= |string| <=100000
Output Format
For each test case, print the required output in a separate line.
Sample TestCase 1
Input
2gqtrawqfnaxtyyzz
Output
qy
Explanation
Test Case 1: There are 2 q types of people rest all are present alone.
Test Case 2: There are 2 y and 2 z types of people. Since the maximum value is same, the type with lesser Ascii value is considered as output. Therfore, y is the correct type.
note:-BusinessLogics–it’s an interface class(you need to define) or in one class you can create.
Scanner sc=new Scanner(System.in);
int numberOfTest=sc.nextInt();
for(int i1=0; i1<numberOfTest; i1++)
{
Scanner sc1=new Scanner(System.in);
String str=sc1.nextLine();
System.out.println(“max type
ppl>>>>>>>>>>”+BusinessLogics.findMaxType(str));
}
above lines would be in main class.