KCE_0001-Editorial

Strong Password
Inception

Setter : harijey
Tester : rohinth_076
Editorialist: harijey

DIFFICULTY:

Simple

PREREQUISITES:

None

PROBLEM:

Sinamkia wants to have a strong password for her social networking accounts so she decides to have fun with it. She chooses a string ‘S’ and then she shuffles the characters of the string randomly and then adds an extra character at the end of it. Your task is to find that extra character.

Input Format

  • First line will contain Password String SS
  • Second line will contain Shuffled String TT

Output Format

Output a single extra character from TT

Constraints

  • 1≤Len(S)≤10001≤Len(S)≤1000
  • Len(T)==Len(S)+1Len(T)==Len(S)+1

Sample Input 1

belows
elxbows

Sample Output 1

x

Explanation:

The given two strings are anagrams if no extra character is appended.

import java.io.*;
import java.util.*;
class Solution{
	static Scanner fs  = new Scanner(System.in);
	static PrintWriter out = new PrintWriter(System.out);

	public static void main(String[] args) {
	   char[] a = fs.next().toCharArray();
       char[] b =fs.next().toCharArray();
       
       Arrays.sort(a);
       Arrays.sort(b);
       int n = a.length;
       char ans = b[n];
       
       for(int i=0;i<n;i++)
        if(a[i] != b[i]){
            ans = b[i];
            break;
        }
        out.println(ans);
        out.flush();
	}
}