Iterate over the string with increment of K
for j in range ( i , N , K ) : NEW_LINE INDENT if S [ j ] in M : NEW_LINE INDENT M [ S [ j ] ] += 1 NEW_LINE DEDENT else : NEW_LINE INDENT M [ S [ j ] ] = 1 NEW_LINE DEDENT DEDENT