Calculating prefix sum over this frequency array to get frequency of a character in a range [ L , R ] .
for i in range ( 26 ) : NEW_LINE INDENT for j in range ( 1 , n ) : NEW_LINE INDENT f [ i ] [ j ] += f [ i ] [ j - 1 ] NEW_LINE DEDENT DEDENT