Strong Password

Sort by

recency

|

924 Discussions

|

  • + 0 comments
    def minimumNumber(n, password):
        # Return the minimum number of characters to make the password strong
        len_required = 6
        has_digit = False
        has_lower_case = False
        has_upper_case = False
        has_special_char = False 
        special_char = set("!@#$%^&*()-+")
        char_required = 4
        for i in password:
            if "0" <= i <= "9" and not has_digit:
                has_digit = True
                char_required -= 1
            elif "a" <= i <= "z" and not has_lower_case:
                has_lower_case = True
                char_required -= 1
            elif "A" <= i <= "Z" and not has_upper_case:
                has_upper_case = True
                char_required -= 1
            elif i in special_char and not has_special_char:
                has_special_char = True
                char_required -= 1
                
        if n >= len_required:
            return char_required
            
        len_diff = len_required - n
                     
        return len_diff if len_diff > char_required else char_required
    
  • + 0 comments

    **Here is problem solution in python java c++ c and Javascript **- https://programmingoneonone.com/hackerrank-strong-password-problem-solution.html

  • + 0 comments

    Python 3

    def minimumNumber(n, password):
        count = 0
        
        if not any(i.isdigit() for i in password):
            count += 1
        if not any(i.islower() for i in password):
            count += 1
        if not any(i.isupper() for i in password):
            count += 1
        if not any(i in "!@#$%^&*()-+" for i in password):
            count += 1
            
        return max(6 - n, count)
    
  • + 0 comments

    Here is my c++ solution, the explanation is here : https://youtu.be/t0O-Knlq4lQ

    char getNature(char c){
        if(c >= '0' && c <='9') return 'n';
        if(c >= 'a' && c <= 'z') return 'l';
        if(c >= 'A' && c <= 'Z') return 'u';
        return 's';
    }
    
    int minimumNumber(int n, string password) {
        map<char, int> mp;
        for(char c: password){
            mp[getNature(c)] = 1;
        }
        return max(4 - (int)mp.size(), 6 - n); 
    }
    
  • + 0 comments

    C#

    int otherCharsRequired = 0;
            if (!password.Any(c => char.IsUpper(c)))
                otherCharsRequired++;
            if (!password.Any(c => char.IsLower(c)))
                otherCharsRequired++;
            if (!password.Any(c => char.IsNumber(c)))
                otherCharsRequired++;
                
            char[] symbols = new char[]{ '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '-', '+' };
            if (!password.Any(c => symbols.Contains(c)))
                otherCharsRequired++;
            
            int charsForMinlength = 6 - n;
            
            return otherCharsRequired > charsForMinlength ? otherCharsRequired : charsForMinlength;