public class Solution {
public static String solution(String str1, String str2){
Queue<Character> queue = new LinkedList<>();
String answer = "YES";
for(int i=0; i< str1.length(); i++){
char element = str1.charAt(i);
queue.add(element);
}
for(int i=0; i<str2.length(); i++){
char element = str2.charAt(i);
if(queue.contains(element)){
if(element!= queue.poll()){
answer = "NO";
break;
}
}
if(!queue.isEmpty()){
answer = "NO";
}
}
return answer;
}
public static void main(String[] args) {
Solution T = new Solution();
String str1 = "CBA";
String str2 = "CBDAGE";
System.out.println(T.solution(str1,str2));
}
}