'triangle' and 'integral'
'listen' and 'silent'
Since it is a binary problem, there is no partial marking. Marks will only be awarded if you get all the test cases correct.
The first and the only line of input contains two single space-separated strings Str1 and Str2, respectively.
Neither of the two input strings contains spaces in between, except to differentiate one from the other.
Also, both the strings will be in lowercase characters.
The only line of output contains either True or False. True, if the given two strings form an anagram pair and False otherwise.
You don't have to explicitly print by yourself. It has already been taken care of.
1 <= N <= 10^5
1 <= M <= 10^5
Where N and M are the lengths of the strings str1 and str2 , respectively.
Time Limit: 1sec
Anagrams have a unique property: the counts of each distinct character present in both strings are the same. One way to check this is:
Frequency of ‘c’ in first string - Frequency of ‘c’ in second string = -2
2. To create this array, first initialize an array of size 26 and fill it with zeros.
3. Iterate through the characters of the first string and increase the element at the corresponding location by 1. For example if the current character is denoted by ‘c’ and the array by arr, then you’ll do arr['c' - ‘a’] += 1. This works because all characters are lowercase.
4. Then repeat the previous step for the second array but this time, decrease the element at the corresponding location by 1
5. Now iterate through the array and see if all elements in it are zero. If any one element is non zero, then the strings are not anagrams. Otherwise, they are anagrams
Divisible Substrings
Ninja and Numbers
Longest Palindromic Substring
Cakes
1-3 Palindrome