Computer Science, asked by rakeshku844, 4 months ago

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 ile 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.​

Answers

Answered by tanvirmorth
6

Answer:

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

Answered by sujan3006sl
0

Answer:

import java.io.*;

import java.util.*;

public class CandidateCode {

  static void characterCount(String inputString)

  {

      HashMap charCountMap = new HashMap();

      char[] strArray = inputString.toCharArray();

      for (char c : strArray) {

          if (charCountMap.containsKey(c)) {

              charCountMap.put(c, charCountMap.get(c) + 1);

          }

          else {

              charCountMap.put(c, 1);

          }

      }

      int max = 0;

      for (Map.Entry entry : charCountMap.entrySet()) {

          int a = Integer.parseInt(String.valueOf(entry.getValue()));

          if(a > max)

          {

              max = a;

          }

      }

      for (Map.Entry entry : charCountMap.entrySet()) {

          int a = Integer.parseInt(String.valueOf(entry.getValue()));

          if(a == max)

          {

              System.out.println(entry.getKey() );

              break;

          }

      }

   }

  public static void main(String args[] ) throws Exception {

      Scanner sc = new Scanner(System.in);

      int t = sc.nextInt();

      for(int i = 0 ; i < t ; i++)

      {

          String str = sc.next();

          characterCount(str);

      }

 }

}

Explanation:

  • Test Case 1: There are two categories of persons there, the remainder of them are all alone.
  • Test Case 2: There are two categories of people: y and z. Because the maximum value is the same, the type with the lower Ascii value is used as the output. As a result, the right type is y.

#SPJ2

Similar questions