Check Permutation
You have been given two strings 'STR1' and 'STR2'. You have to check whether the two strings are anagram to each other or not.
Note:
Two strings are said to be anagram if they contain the same characters, irrespective of the order of the characters.
Example :
If 'STR1' = “listen” and 'STR2' = “silent” then the output will be 1.
Both the strings contain the same set of characters.
Input Format:
The first line contains an integer ‘T’ which denotes the number of test cases.
The first and only line of each test case contains two space-separated strings 'STR1' and 'STR2', respectively.
Output Format:
For each test case, return true if the two strings are anagrams of each other else return false.
Print the output of each test case in a separate line.
Constraints:
1 <= T <= 100
1 <= |STR1|, |STR2| <= 10^3
Where |STR1| and |STR2| are the lengths of the string 'STR1' and 'STR2' respectively.
Time limit: 1 sec
CodingNinjas
author
2y
Brute-Force
The basic idea of this approach is to sort both the strings and compare the characters of the sorted strings.
- Sort both strings.
- Compare the characters of the sorted strings.
CodingNinjas
author
2y
Hashing
The idea is to create a ‘HASH’ array with all the values initialized to 0. We increment the value in the ‘HASH’ array for characters in 'STR1' and decrement for characters in ‘STR1’. Finally, i...read more
Help your peers!
Add answer anonymously...
Top VMware Software Member Technical Staff interview questions & answers
Popular interview questions of Member Technical Staff
Top HR questions asked in VMware Software Member Technical Staff
>
VMware Software Member Technical Staff Interview Questions
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app