Anagram Pairs

Pre-requisites: Anagrams are defined as words or names that can be formed by rearranging letters of another word. Such as "spar" can be formed by rearranging letters of "rasp". Hence, "spar" and "rasp" are anagrams.

Other examples include:

'triangle' and 'integral'
'listen' and 'silent'

Now, Coding Ninjas has the following task for you:

You would be given two strings. You have to tell whether these strings form an anagram pair or not. The strings form an anagram pair if the letters of one string can be rearranged to form another string.

Note:
Since it is a binary problem, there is no partial marking. Marks will only be awarded if you get all the test cases correct. 
Input format:
The first and the only line of input contains two single space-separated strings Str1 and Str2, respectively.
Remember/Consider:
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.
Output format:
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.   
Constraints:
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
CodingNinjas
author
2y

1)Take Input two strings ‘a’ and ‘b’
2)A function checkStringAnagrams(string a, string b) which will return true if they are anagram of each other otherwise false.
3)Find the length of both strings and ...read more

CodingNinjas
author
2y
Count Characters

Anagrams have a unique property: the counts of each distinct character present in both strings are the same. One way to check this is:

  1. Sort both strings, so that all the same character...read more
CodingNinjas
author
2y
Frequency Array Approach
  1. Create a 26 sized array. Each element A[i] of the array stores the difference of the frequencies of the (i + 1)th alphabet in the strings.
    At i=0, frequency of ‘a’ is stored be...read more
Add answer anonymously...
Ernst & Young Senior Software Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
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

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter