DEV Community

Thivyaa Mohan
Thivyaa Mohan

Posted on

4 2

2299. Strong Password Checker II

A password is said to be strong if it satisfies all the following criteria:

It has at least 8 characters.
It contains at least one lowercase letter.
It contains at least one uppercase letter.
It contains at least one digit.
It contains at least one special character. The special characters are the characters in the following string: "!@#$%^&*()-+".
It does not contain 2 of the same character in adjacent positions (i.e., "aab" violates this condition, but "aba" does not).
Given a string password, return true if it is a strong password. Otherwise, return false

class Solution {
public:
    bool strongPasswordCheckerII(string &p) {
        if(p.size()<8) return false;
        bool low =false, upper = false,digit = false,special =false;
        for(auto it:p){
            if(it>='a' and it<='z')low = true;
        else if(it>='A' and it<='Z')upper = true;
        else if(isdigit(it)) digit = true;
            else special = true;

        }
        //check the 6th condition 
        for(int i=0;i+i<p.size();i++) if(p[i] == p[i+1]) return false;
        if(low and upper and special and digit) return true;
        return false;

    }
};
Enter fullscreen mode Exit fullscreen mode

AWS GenAI LIVE image

Real challenges. Real solutions. Real talk.

From technical discussions to philosophical debates, AWS and AWS Partners examine the impact and evolution of gen AI.

Learn more

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay