Traverse the substring S [ l , r ] to find the frequency of 1 s and 0 s in it
for i in range ( l - 1 , r ) : NEW_LINE INDENT if ( s [ i ] == '1' ) : NEW_LINE INDENT ones += 1 NEW_LINE Sum += 1 NEW_LINE DEDENT else : NEW_LINE INDENT zeros += 1 NEW_LINE DEDENT DEDENT