2 different strings were given and the question is to find out the minimum number of deletion from the given string to make both strings anagrams. I came to see this code snippet some where and all my test cases has passed, but could not understand the logic. That is, why is it subtracting 'a'? and what will be the result of it. It would be so helpful if somebody explains me the code. Thanks in advance.
int[] array=new int[26];
for(int i=0;i<s1.Length;i++)
array[s1[i]-'a']++;
for(int i=0;i<s2.Length;i++)
array[s2[i]-'a']--;
int sum = 0;
for(int i=0;i<26;i++)
sum+=Math.Abs(array[i]);
return sum;