##### Welcome to Subscribe On Youtube

Formatted question description: https://leetcode.ca/all/2299.html

# 2299. Strong Password Checker II

• Difficulty: Easy.
• Related Topics: String.

## Problem

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. Example 1: Input: password = "IloveLe3tcode!" Output: true Explanation: The password meets all the requirements. Therefore, we return true.  Example 2: Input: password = "Me+You--IsMyDream" Output: false Explanation: The password does not contain a digit and also contains 2 of the same character in adjacent positions. Therefore, we return false.  Example 3: Input: password = "1aB!" Output: false Explanation: The password does not meet the length requirement. Therefore, we return false.  Constraints: • 1 <= password.length <= 100 • password consists of letters, digits, and special characters: "!@#$%^&*()-+".

## Solution (Java, C++, Python)

• class Solution {
return false;
}
boolean l = false;
boolean u = false;
boolean d = false;
boolean s = false;
String special = "!@#\$%^&*()-+";
char previous = '.';
for (int i = 0; i != password.length(); i++) {
if (ch == previous) {
return false;
}
previous = ch;
if (ch >= 'A' && ch <= 'Z') {
u = true;
} else if (ch >= 'a' && ch <= 'z') {
l = true;
} else if (ch >= '0' && ch <= '9') {
d = true;
} else if (special.indexOf(ch) != -1) {
s = true;
}
}
return l && u && d && s;
}
}

############

class Solution {
return false;
}
for (int i = 0; i < password.length(); ++i) {
if (i > 0 && c == password.charAt(i - 1)) {
return false;
}
if (Character.isLowerCase(c)) {
} else if (Character.isUpperCase(c)) {
} else if (Character.isDigit(c)) {
} else {
}
}
}
}

• class Solution:
return False
if i and c == password[i - 1]:
return False
if c.islower():
elif c.isupper():
elif c.isdigit():
else:

############

# 2299. Strong Password Checker II

class Solution:
if n < 8: return False

lower = upper = numbers = special = 0

if index + 1 < n and x == password[index + 1]:
return False

if x in string.ascii_letters:
if x.islower():
lower += 1
else:
upper += 1
elif x.isdigit():
numbers += 1
else:
special += 1

return lower > 0 and upper > 0 and numbers > 0 and special > 0


• class Solution {
public:
return false;
}
for (int i = 0; i < password.size(); ++i) {
if (i && c == password[i - 1]) {
return false;
}
if (c >= 'a' && c <= 'z') {
} else if (c >= 'A' && c <= 'Z') {
} else if (c >= '0' && c <= '9') {
} else {
}
}
}
};

• func strongPasswordCheckerII(password string) bool {
return false
}
for i, c := range password {
if i > 0 && byte(c) == password[i-1] {
return false
}
if unicode.IsLower(c) {
} else if unicode.IsUpper(c) {
} else if unicode.IsDigit(c) {
} else {
}
}
}

• function strongPasswordCheckerII(password: string): boolean {
return false;
}
for (let i = 0; i < password.length; ++i) {
if (i && c == password[i - 1]) {
return false;
}
if (c >= 'a' && c <= 'z') {
} else if (c >= 'A' && c <= 'Z') {
} else if (c >= '0' && c <= '9') {
} else {
}
}
}


• impl Solution {
if n < 8 {
return false;
}
let mut prev = b' ';
for &c in s.iter() {
if c == prev {
return false;
}
0b1000
} else if c.is_ascii_lowercase() {
0b100
} else if c.is_ascii_digit() {
0b10
} else {
0b1
};
prev = c;
}
}
}



Explain:

nope.

Complexity:

• Time complexity : O(n).
• Space complexity : O(n).