Problem Description
Given a password string, determine if it is strong by ensuring it meets all of 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 from the set "!@#$%^&*()-+".
- It does not contain two identical characters in adjacent positions.
Key Insights
- Validate the minimum length requirement before processing further.
- Use boolean flags to track the presence of lowercase, uppercase, digits, and special characters.
- Efficiently detect two identical consecutive characters by comparing the current character to the previous one.
- Use a set or direct lookup to verify if a character is a special character.
Space and Time Complexity
Time Complexity: O(n), where n is the length of the password. Space Complexity: O(1), since only constant extra space is used for flags and helper structures.
Solution
The solution involves a single pass through the password string to check all the necessary conditions:
- Verify if the password meets the minimum length.
- Traverse each character:
- Check for consecutive identical characters.
- Update flags to confirm the existence of lowercase letters, uppercase letters, digits, and special characters.
- After the iteration, validate that all required flags are true.
- Return the result accordingly.