FastPrepClassify Password Strength

Classify Password Strength

HackerRank logoHackerRank● MediumINTERNONSITE INTERVIEW
Learn

Problem statement

Classify every string in passwords as "weak" or "strong".

A password is weak when it has fewer than six characters, consists entirely of digits, entirely of lowercase letters, or entirely of uppercase letters, or contains any string from commonWords as a case-sensitive substring. Otherwise it is strong. Return classifications in input order.

Function

classifyPasswords(passwords: String[], commonWords: String[]) → String[]

Examples

Example 1

passwords = ["abc123","ABCDEF","Abc!23"]commonWords = ["password"]return = ["strong","weak","strong"]

The mixed alphanumeric and mixed-symbol passwords pass, while the all-uppercase password is weak.

Example 2

passwords = ["mySecret1","safeA1"]commonWords = ["Secret"]return = ["weak","strong"]

The first password contains a blocked substring with matching case.

Constraints

  • 1 <= passwords.length <= 1000.
  • 0 <= passwords[i].length <= 1000.
  • 0 <= commonWords.length <= 1000, and every common word is nonempty.
  • Inputs contain ASCII characters, and substring matching is case-sensitive.

More HackerRank problems

See HackerRank hiring insights
public String[] classifyPasswords(String[] passwords, String[] commonWords) {
    // Write your code here.
}
passwords["abc123","ABCDEF","Abc!23"]
commonWords["password"]
expected["strong", "weak", "strong"]
Checking account…