Is there a way to check if two strings contain the same characters. For example,
abc, bca -> true
aaa, aaa -> true
aab, bba -> false
abc, def ->
This problem can be simply solved in O(n) time and O(1) space. The idea is to use a temp array of size 26 as we have only 26 characters in the alphabet.
First, if length of both strings are different we immediately return false. We iterate over length of the given string and in temp array, increase frequency of every character in string one and decrease count of character occured in other string. At the end temp array should have 0 count for every character if strings have equal characters.