Check Permutation
Problem Statement
Suggest Edit
Problem Statement
Two strings are said to be a permutation of each other when either of the string's characters can be rearranged so that it becomes identical to the other one.
Example:
str1= "sinrtg"
str2 = "string"
The character of the first string(str1) can be rearranged to form str2 and hence we can say that the given strings are a permutation of each other.
The first line of input contains a string without any leading and trailing spaces, representing the first string 'str1'.
The second line of input contains a string without any leading and trailing spaces, representing the second string 'str2'.
All the characters in the input strings would be in lower case.
The only line of output prints either 'true' or 'false', denoting whether the two strings are a permutation of each other or not.
You are not required to print anything. It has already been taken care of. Just implement the function.
0 <= N <= 10^6
Where N is the length of the input string.
Time Limit: 1 second
abcde
baedc
true
abc
cbd
false
def isPermutation(string1, string2) : lis1=list(string1) lis1.sort() lis2=list(string2) lis2.sort() if lis1==lis2: return True else: return False #Your code goes here #main string1 = input() string2 = input() ans = isPermutation(string1, string2) if ans : print('true') else : print('false')
Comments
Post a Comment