Leetcode 2299: Strong Password Checker II

grid47
grid47
Exploring patterns and algorithms
Mar 22, 2024 6 min read

A strong password is defined by the following criteria:

  1. It must contain at least 8 characters.
  2. It must have at least one lowercase letter.
  3. It must have at least one uppercase letter.
  4. It must have at least one digit.
  5. It must have at least one special character from the set: ‘!@#$%^&*()-+’.
  6. It cannot contain two consecutive identical characters. Given a string password, return true if the password satisfies all these conditions. Otherwise, return false.
Problem
Approach
Steps
Complexity
Input: The input consists of a string `password` containing letters, digits, and special characters from the set: '!@#$%^&*()-+'.
Example: Input: password = 'Secure123!'
Constraints:
• 1 <= password.length <= 100
• The password consists only of letters, digits, and the special characters '!@#$%^&*()-+'.
Output: Return `true` if the password is strong according to the conditions outlined. Otherwise, return `false`.
Example: Output: true
Constraints:
Goal: To verify whether a given password meets all the criteria for being strong.
Steps:
• Step 1: Check if the password has at least 8 characters.
• Step 2: Verify that the password contains at least one lowercase letter, one uppercase letter, one digit, and one special character from the specified set.
• Step 3: Ensure that no two adjacent characters in the password are the same.
• Step 4: Return `true` if all conditions are met; otherwise, return `false`.
Goal: The password must adhere to the constraints mentioned, including having the required length, character types, and no adjacent duplicate characters.
Steps:
Assumptions:
• The password contains at least one character and does not exceed 100 characters.
• The password includes a mix of letters, digits, and special characters as per the specified set.
Input: Input: password = 'Password123!'
Explanation: This password meets all the criteria: it has 12 characters, includes lowercase, uppercase, a digit, a special character, and no adjacent identical characters.

Input: Input: password = '12345abc!'
Explanation: This password fails because it doesn't contain an uppercase letter, though it meets other conditions.

Link to LeetCode Lab


LeetCode Solutions Library / DSA Sheets / Course Catalog
comments powered by Disqus