Grokking the Coding Interview: Patterns for Coding Questions
Ask Author
Back to course home

0% completed

Vote For New Content
Why is right_char frequency initialized to 0 as we add it to the char_frequency ...

Dale

May 18, 2022

Why is right_char frequency initialized to 0 as we add it to the char_frequency = {}

0

0

Comments
Comments
D
Dale 3 years ago
Design Gurus
Design Gurus3 years ago

In the 'for' , we are calculating the frequency of each character.

The 'if' statement checks if it is a new character, if so, simply insert it into the dictionary and set the frequency to '0' (we could set it to '1').

The next line (which is not under the 'if'), incre...

On this page