Kindly tell me why in the video of First Non repeating character in a stream implementation (Queues) in line 15 why he subtracted ‘a’ from qu.front() . Please explain it
Doubt in a line of code while explanation
@Ramitgoel In this case, Sanket bhaiya is considering small case characters from a to z. ascii code of a is 97 and z is 122. All characters a to z have ascii code in between 97 to 122.
Here we are maintaining a map of the frequency of occurance based on the ascii value.
So line number 15: if(mp[qu.front()-‘a’]>1)
if front element of the queue contains ‘b’ then ‘b’-‘a’ is equivalent to 98-97=1 so it will check if mp[1]>1
if true then you can say that the character is repeated.
Hope this helps