Program to check if two strings are anagrams or not is discussed here. Two strings are given as input and those strings have to be checked if they are anagrams or not. Anagram means that both strings contain the same character set, only their order is different. Therefore, in both strings, the frequency of each letter must be the same. For example, strings “act” and “cat” are anagrams.
Method 1: Count the frequency of alphabets in both the strings and store them in respective arrays. If the two arrays are equal, return true. Else, return false.
Method 2: Sort both the strings and compare if both the sorted strings are equal. If they are equal, return true. Else, return false
@@coding::2@@
@@coding::1@@
Recommended Programs