Strong Password

Sort by

recency

|

913 Discussions

|

  • + 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

    Here is my Python solution!

    def minimumNumber(n, password):
        specials = ["!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "-", "+"]
        upper = False
        lower = False
        special = False
        num = False
        for letter in password:
            if letter.isupper():
                upper = True
            elif letter.islower():
                lower = True
            elif letter.isnumeric():
                num = True
            elif letter in specials:
                special = True
        return max(0, 6 - n, [upper, lower, special, num].count(False))
    
  • + 0 comments

    Python solution using Hash Map:

    special_characters = "!@#$%^&*()-+"
        hash_map={"num":0, "low":0, "up":0,"spcl": 0}
        for letter in password:
            if letter.islower():
                hash_map["low"]+=1
            if letter.isupper():
                hash_map["up"]+=1
            if letter.isdigit():
                hash_map["num"]+=1
            if letter in special_characters:
                hash_map["spcl"]+=1
            
        # print(hash_map)
        count=0      
        for val in hash_map.values():
            if val == 0:
                count+=1
      
        if n+count<6:
            rem_dig=6-(n+count)
            count+=rem_dig
       
        return count
              
    
  • + 1 comment
    def minimumNumber(n, password):
        a=0
        b=0
        e=0
        c=0
        d=0
        for i in password:
           if i.isdigit():
               a=1
           elif i.islower():
               b=1
           elif i.isupper():
               c=1
           elif i in "!@#$%^&*()-+":
               d=1
        a=4-(a+c+d+b)
        if n<6:
           e=6-n
        if a>e:
            return a
        else:
            return e
        if e==a:
            return a
    
  • + 0 comments

    MY SOLUTION -- USING REGEX PATTERN IN JAVA

    Pattern num_regex = Pattern.compile("[0-9]");
        Pattern small_alpha_regex = Pattern.compile("[a-z]");
        Pattern cap_alpha_regex = Pattern.compile("[A-Z]");
        Pattern special_regex = Pattern.compile("[-!@#$%^&*()-+]");
    
        int min_len = 6;
        int count = 0;
        if (num_regex.matcher(password).find() && small_alpha_regex.matcher(password).find()
                && cap_alpha_regex.matcher(password).find() && special_regex.matcher(password).find() && n < min_len) {
            while (n != min_len) {
                n++;
                count++;
            }
        }
    
        if (!num_regex.matcher(password).find())
            count++;
        if (!small_alpha_regex.matcher(password).find())
            count++;
        if (!cap_alpha_regex.matcher(password).find())
            count++;
        if (!special_regex.matcher(password).find())
            count++;
    
        n += count;
        if (n >= min_len)
            return count;
        while (n != min_len) {
            n++;
            count++;
        }
        return count;