
Problem
Solution
Submissions
Strong Password Checker
Certification: Advanced Level
Accuracy: 0%
Submissions: 0
Points: 15
Write a C program to check if a password is strong and return the minimum number of steps required to make it strong. A password is considered strong if it satisfies ALL of the following criteria:
- It has at least 6 characters and at most 20 characters.
- It contains at least one lowercase letter, at least one uppercase letter, and at least one digit.
- It does not contain three repeating characters in a row (i.e., "...aaa..." is weak, but "...aa...a..." is strong, assuming other conditions are met).
You can perform the following operations: Insert a character to any position, Delete a character from any position, Replace a character at any position.
Example 1
- Input: password = "a"
- Output: 5
- Explanation:
- Password length is 1, needs at least 6 characters.
- Missing uppercase letter and digit.
- Need to add 5 characters to reach minimum length while satisfying missing type requirements.
- Password length is 1, needs at least 6 characters.
Example 2
- Input: password = "aaaaaaaaaaaaaaaaaaaaa"
- Output: 7
- Explanation:
- Password length is 21, exceeds maximum of 20.
- Has lowercase but missing uppercase and digit.
- Has repeating characters "aaa" multiple times.
- Need to delete 1 character and replace others to fix issues.
- Password length is 21, exceeds maximum of 20.
Constraints
- 1 ≤ password.length ≤ 50
- password consists of only English letters and digits
- You can perform insert, delete, or replace operations
- Time Complexity: O(n) where n is password length
- Space Complexity: O(1)
Editorial
My Submissions
All Solutions
Lang | Status | Date | Code |
---|---|---|---|
You do not have any submissions for this problem. |
User | Lang | Status | Date | Code |
---|---|---|---|---|
No submissions found. |
Solution Hints
- Check the length first - if too short, calculate additions needed
- If too long, calculate deletions needed and prioritize fixing repeating sequences
- Count missing character types (lowercase, uppercase, digit)
- Handle repeating sequences by counting groups of 3+ consecutive characters
- For short passwords, additions can fix both length and missing types
- For long passwords, deletions and replacements should be optimized
- Use greedy approach to minimize total operations