You are viewing a single comment's thread. Return to all comments →
public static int minimumNumber(int n, string password) { // Return the minimum number of characters to make the password strong List<char> distinctChars = password.Distinct().ToList<char>(); int charsToBeAdded = 0; if(!distinctChars.Exists(x => Char.IsAsciiDigit(x) == true)) { charsToBeAdded++; } if(!distinctChars.Exists(x => Char.IsAsciiLetterLower(x) == true)) { charsToBeAdded++; } if(!distinctChars.Exists(x => Char.IsAsciiLetterUpper(x) == true)) { charsToBeAdded++; } if(!distinctChars.Exists(x => Char.IsAsciiLetterOrDigit(x) == false && Char.IsWhiteSpace(x) == false)) { charsToBeAdded++; } const int minPasswordLength = 6; if(password.Length > minPasswordLength) { return charsToBeAdded; } else { int difference = minPasswordLength - password.Length; if(difference > charsToBeAdded) { return difference; } else { return charsToBeAdded; } } }
Seems like cookies are disabled on this browser, please enable them to open this website
I agree to HackerRank's Terms of Service and Privacy Policy.
Strong Password
You are viewing a single comment's thread. Return to all comments →