Strong Password

  • + 0 comments

    Python 3:

    numbers = {*"0123456789"}
    lower_case = {*"abcdefghijklmnopqrstuvwxyz"}
    upper_case = {*"ABCDEFGHIJKLMNOPQRSTUVWXYZ"}
    special_characters = {*"!@#$%^&*()-+"}
    
    
    def minimumNumber(n: int, password: str) -> int:
        # Return the minimum number of characters to make the password strong
        if n < 3:
            return 6 - n
        characters = {*password}
        return max(
            sum(
                not (characters & char_class)
                for char_class in (numbers, lower_case, upper_case, special_characters)
            ),
            6 - n,
        )