I use two 26 element arrays in my program.
What is the time and space complexity for this program to find if a string is an anagram of another?
int arr1[26] = { 0 };
int arr2[26] = { 0 };
for (char& x : s)
arr1[x - 'a']++;
for (char& x : t)
arr2[x - 'a']++;
for (int i = 0; i < 26; i++) {
if (arr1[i] != arr2[i])
return false;
}
return true;