Frequency of array

i didn’t understand this syntax which is stated in that video
syntax:
for(int i=0;i<l1;i++)
{
freq[s1[i]-‘a’]++;
}

@tharun
Hello Tharun,
in the given syntax we are traversing the string s1 and incrementing the count of character s1[i] by one at index s1[i]-‘a’.

s1[i]-‘a’ is giving us index where we need to increment.

for example
if s1[i]==‘a’ then s1[i]-‘a’ =0 means increment freq[0] by 1
if s1[i]==‘b’ then s1[i]-‘a’ =1 means increment freq[1] by 1
if s1[i]==‘c’ then s1[i]-‘a’ =2 means increment freq[2] by 1
so on

@tharun
Hello tharun,
if u still have any doubt in this then please let me know

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.