Check a Password Against a Supplied Policy
Updated
Problem statement
Return whether password satisfies the policy supplied by minimumLength, requireLowercase, requireUppercase and requireDigit.
For this exercise, assume the password contains only printable ASCII characters, with codes 32 through 126. Its length must be at least minimumLength. For each flag set to true, the password must also contain at least one character of that type: lowercase a through z, uppercase A through Z, or digit 0 through 9. A flag set to false adds no requirement.
For this exercise, assume other printable characters, including spaces and punctuation, are allowed and count toward length; they satisfy none of those three classes. Return true exactly when every enabled requirement passes. An empty password passes only when the minimum is zero and all class flags are false. Do not modify the input.
Function
checkPassword(password: String, minimumLength: int, requireLowercase: boolean, requireUppercase: boolean, requireDigit: boolean) → booleanExamples
Example 1
password = "aA0"minimumLength = 3requireLowercase = truerequireUppercase = truerequireDigit = truereturn = trueThe length is three and the password contains a lowercase letter, an uppercase letter and a digit.
Example 2
password = "hello"minimumLength = 5requireLowercase = truerequireUppercase = truerequireDigit = falsereturn = falseThe length and lowercase check pass, but the enabled uppercase requirement fails.
Example 3
password = ""minimumLength = 0requireLowercase = falserequireUppercase = falserequireDigit = falsereturn = trueAn empty string meets the zero minimum and has no enabled class checks.
Constraints
- For this exercise, assume
0 <= password.length <= 500. - For this exercise, assume
0 <= minimumLength <= 500. - Every password character is printable ASCII, from code
32through126. - The three class parameters are Boolean flags.
More Walmart Phone Screen questions
- Count Months Starting on SundayPHONE SCREEN · Seen Aug 2026
- Longest Even-Length WordPHONE SCREEN · Seen Aug 2026
- Range ModulePHONE SCREEN · Seen Aug 2026
- Meeting Rooms IIPHONE SCREEN · Seen Aug 2026
- Sort Real Number StringsPHONE SCREEN · Seen Jan 2026
- Convert a Restricted Function to an Arrow FunctionPHONE SCREEN · Seen Jun 2025
- Repair One Missing Function Punctuation CharacterPHONE SCREEN · Seen Jun 2025
- Can the Singer Perform the Song?PHONE SCREEN · Seen Mar 2025
- Rooms With Two Other Entrances and a Treasure SuccessorPHONE SCREEN · Seen Mar 2025
- First Dictionary Word from Note LettersPHONE SCREEN · Seen Aug 2022
Similar questions at other companies
- Run-Length Encoding and DecodingAirbnb · PHONE SCREENAirbnb interview questions
- Straight-Line Word SearchReddit · PHONE SCREENReddit interview questions
- Search and Format ContactsAdyen · PHONE SCREENAdyen interview questions
- Subtract Two Large Number StringsStackAdapt · PHONE SCREENStackAdapt interview questions
- Transaction Fee Calculator — Parts 1–2: Basic Fee Calculation and Conditional Fee RulesStripe · PHONE SCREENStripe interview questions
- Valid ParenthesesByteDance · PHONE SCREENByteDance interview questions
- Detect a Straight FlushTemu · PHONE SCREENTemu interview questions
- Check if a String Is a PalindromeCisco · PHONE SCREENCisco interview questions
- Halfway Course in a Single TrackCrunchyroll · PHONE SCREENCrunchyroll interview questions
- Longest Common PrefixKotak Mahindra Bank · PHONE SCREEN · ONSITE INTERVIEWKotak Mahindra Bank interview questions