Created
January 21, 2020 13:26
-
-
Save Chaitanya2801/cd5ddfbda12611bcafbb23d42b06bb56 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Arrays; | |
import java.util.HashMap; | |
import java.util.Map; | |
import java.util.Scanner; | |
public class Runnersup { | |
public static void main(String[] args) { | |
Scanner sc=new Scanner(System.in); | |
int zz=sc.nextInt(); | |
sc.nextLine(); | |
for (int i = 0; i < zz; i++) { | |
String s[]=sc.nextLine().split(""); | |
Arrays.sort(s); | |
HashMap<Integer,String> m=new HashMap<>(); | |
String ss=s[0]; | |
int c=0; | |
int j=-1; | |
while(++j<s.length-1) { | |
if (j < s.length && ss.equals(s[j])) { | |
++c; | |
} else if (j < s.length && !ss.equals(s[j])) { | |
m.put(c, s[j - 1]); | |
ss = s[j]; | |
c = 1; | |
} else | |
m.put(c, s[j - 1]); | |
} | |
if(m.size()==1) | |
System.out.println("-1"); | |
else{ | |
int f=1; | |
for (Map.Entry<Integer,String> mm: m.entrySet()){ | |
if (f==m.size()-1){ | |
System.out.println(mm.getValue()); | |
break; | |
} | |
++f; | |
} | |
} | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Try commenting your code a little bit, it is illegible