Strong Password

  • + 0 comments

    Python solution

    def minimumNumber(n, password):
        # Return the minimum number of characters to make the password strong
        numbers = "0123456789"
        lower_case = "abcdefghijklmnopqrstuvwxyz"
        upper_case = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
        special_characters = "!@#$%^&*()-+"
        
        not_spl = 1
        not_lower = 1
        not_upper = 1
        not_num = 1
        
        for i in range(n):
            if not_num and password[i] in numbers:
                not_num = 0
            elif not_lower and password[i] in lower_case:
                not_lower = 0
            elif not_upper and password[i] in upper_case:
                not_upper = 0
            elif not_spl and password[i] in special_characters:
                not_spl = 0
        
        req_char = not_lower + not_num + not_spl + not_upper
        
        if n<6:
            return max(req_char, 6 - n)
        else:
            return req_char