1. Problem + Keyword in solution
2. Pseudocode
3. Stack trace
4. Code
Problem:
Determine the minimum number of changes needed to add password secure
Secure password has:
1. at least 6 characters
2. one uppercase letter
3. one lowercase letter
4. one number
5. one special case letter "!@#$%^&*()-+"
Solution:
If there is one character that matches any of the conditions, than don't increment the counter for non matching characters
compare the non matching characters with current size of password, if password size is less than 6, than you have to add at least 6-n where n is the current size of password. Dependent on if 6-n is bigger or counter is bigger.
Think of test cases and calculate solutions to optimize solution
1. size of pwd is 0
2. size of pwd is 1 or 2
3. size of pwd is 3 but all are non matching
4. size of pwd is 4 but all are matching the special characters
the equation that you come up with
Max of (6- (size of pwd), counter for non matching characters)
No comments:
Post a Comment