Input - "sumit mitsu"
How to find if permutation of anyone of the String is matching the other. Please find my code below on my attempt and help me if my approach is right. I also tried to use Arrays.sort to sort the string but hackerEarth editor is not accepting Arrays.sort. Is there any other approach to solve this? TIA.
Note - This is a hackerEarth two strings problem.
I had split the input two string array. And then I converted each keyword into character array. With for loop i ran through each keyword in S1 to match with S2 array.
class TestClass {
public static void main(String args[] ) throws Exception {
Scanner s = new Scanner(System.in);
int cases=s.nextInt();
for(int i=0;i<cases;i++){ //for multiple lines
String name1=s.nextLine();
String name2=s.nextLine();
char[] n1=name1.toCharArray();
char[] n2=name2.toCharArray();
boolean match=false;
for(int j=0;j<n1.length;j++){
for(int k=0;k<n2.length;k++){
if(n1[j]==n2[k]){
match=true;
break;
}
else{
match=false;
}
}
}
System.out.println(match);
}
}
}
Input - majnu jamnu
Expected - True Actual - False