Iterate till the length of the given string
for i in range ( len ( S ) ) : NEW_LINE INDENT now = ord ( S [ i ] ) - ord ( ' a ' ) NEW_LINE for j in range ( 26 ) : NEW_LINE INDENT dp [ j ] [ now ] += arr [ j ] NEW_LINE DEDENT arr [ now ] += 1 NEW_LINE DEDENT ans = 0 NEW_LINE