Doing binary search on the lengths
while ( l <= r ) : NEW_LINE INDENT mid = ( l + r ) // 2 NEW_LINE if ( check ( s , mid ) ) : NEW_LINE INDENT l = mid + 1 NEW_LINE maxi = max ( maxi , mid ) NEW_LINE DEDENT else : NEW_LINE INDENT r = mid - 1 NEW_LINE DEDENT DEDENT return maxi NEW_LINE