String - Letters comparison - Spicy Coders

Recent

Friday, December 01, 2017

String - Letters comparison

Two string values S1 and S2 are passed as input. The program must check if both S1 and S2 contain the same unique set of letters and print YES or NO. Assume all the letters (alphabets) are in smaller case. 

Boundary Conditions: Length of S1 is from 2 to 100 Length of S2 is from 2 to 100

Input Format: First line will contain the string value of S1 Second line will contain the string value of S2 

Output Format: YES or NO depending on if both S1 and S2 contain the same set of unique letters. IMPORTANT: Please not that the output is CASE SENSITIVE. Hence print YES or NO (instead of yes or no) 

Sample Input/Output: 
Example 1: Input: 
read dear 

Output: 
YES 

Explanation: Both S1 and S2 are formed using the letters - a d e r

Example 2: Input:
record decoder 

Output: 
YES 

Explanation: Both S1 and S2 are formed using the letters - c d e o r 

Example 3: Input:
energy synergy 

Output: 
NO 

Explanation: S2 has additional letters - s y in it.

Source Code: //Python

s1,s2=input().strip(),input().strip()
s1,s2=sorted(set(s1)),sorted(set(s2))
if s1==s2:
    print("YES")
else:

    print("NO")

No comments:

Post a Comment