please explain the logic behind creating the freq array an then why we are subtracting character a from it
Frequency array
hello @dheerajmishra992
a) why we are subtracting ‘a’ ?
see we are using array to store frequency ,and if we store directly (i.e without subtracting ‘a’)
then frequency will be stored at its ascii value but we want to store it from index 0 onwards this is the reason we are subtracting ‘a’.
example->
‘a’-‘a’=0
‘b’-‘a’=1
‘c’-‘a’=2
clearly subtracting ‘a’ is now giving us index from 0 onwards.
so we can say that frequency of character ‘a’ is stored at index 0 of frequency array.
frequency of character ‘b’ is stored at index 1 of frequency array.
frequency of character ‘c’ is stored at index 2 of frequency array.
so on
logic behind creating frequency array?
in question we are asked to find string which contains all unique characters (i.e no character is repeated) .
so using frequency array we are calculating frequency of each character and if we find that any character has frequency greater than 1 then we discard that string.
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.