Validate a Password Against Explicit Security Rules

Quick Overview

Validate a password against explicit length, digit, lowercase, uppercase, special-character, and no-space requirements using the exact permitted special-character set.

Validate a Password Against Explicit Security Rules

Company: DRW

Role: Data Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Online Assessment

## Problem A password is secure when all of the following are true: - It has at least six characters. - It contains at least one digit. - It contains at least one lowercase English letter. - It contains at least one uppercase English letter. - It contains at least one character from the exact special-character set `!@#$%^&*()_`. - It contains no space character. Return whether a supplied password is secure. ### Function Contract Implement `isSecurePassword(password)` and return a Boolean. ### Constraints & Assumptions - `0 <= len(password) <= 100`. - Every character is an English letter, digit, ordinary space, or a member of the special set above. - Only the explicitly listed characters count as special. - A password may contain several characters from each category. ### Clarifying Questions to Ask - Do characters such as `-` or `?` count as special? No. - Does a tab count as a space? Tabs are outside the stated input alphabet; reject only the ordinary space character. - Is six characters inclusive? Yes. - Must every requirement be checked even after one fails? No; early return is allowed. ```hint Track independent facts Maintain one Boolean for each required character category and reject immediately if an ordinary space appears. ``` ### Examples - `"FooBar123!"` returns `true`. - `"foobar123!"` returns `false` because it has no uppercase letter. - `"FooBar123"` returns `false` because it has no listed special character. - `"F0bar! F0bar!"` returns `false` because it contains a space. - `"Fo0*"` returns `false` because it is too short. ### Evaluation Focus - Uses the exact special-character set and the inclusive minimum length. - Rejects spaces even when every positive category is present. - Handles empty and boundary-length strings. - Runs in `O(n)` time and `O(1)` auxiliary space. ### Extensions to Discuss 1. How would Unicode letters change category detection? 2. Why is a configurable policy preferable to embedding many enterprise rules in one regular expression? 3. How would you report every failed rule without leaking the password into logs?

Quick Answer: Validate a password against explicit length, digit, lowercase, uppercase, special-character, and no-space requirements using the exact permitted special-character set.

|Home/Coding & Algorithms/DRW
DRW logo
DRW
May 22, 2026, 12:00 AM
easyData EngineerOnline AssessmentCoding & Algorithms
0
0

Problem

A password is secure when all of the following are true:

  • It has at least six characters.
  • It contains at least one digit.
  • It contains at least one lowercase English letter.
  • It contains at least one uppercase English letter.
  • It contains at least one character from the exact special-character set !@#$%^&*()_ .
  • It contains no space character.

Return whether a supplied password is secure.

Function Contract

Implement isSecurePassword(password) and return a Boolean.

Constraints & Assumptions

  • 0 <= len(password) <= 100 .
  • Every character is an English letter, digit, ordinary space, or a member of the special set above.
  • Only the explicitly listed characters count as special.
  • A password may contain several characters from each category.

Clarifying Questions to Ask Guidance

  • Do characters such as - or ? count as special? No.
  • Does a tab count as a space? Tabs are outside the stated input alphabet; reject only the ordinary space character.
  • Is six characters inclusive? Yes.
  • Must every requirement be checked even after one fails? No; early return is allowed.

Examples

  • "FooBar123!" returns true .
  • "foobar123!" returns false because it has no uppercase letter.
  • "FooBar123" returns false because it has no listed special character.
  • "F0bar! F0bar!" returns false because it contains a space.
  • "Fo0*" returns false because it is too short.

Evaluation Focus

  • Uses the exact special-character set and the inclusive minimum length.
  • Rejects spaces even when every positive category is present.
  • Handles empty and boundary-length strings.
  • Runs in O(n) time and O(1) auxiliary space.

Extensions to Discuss

  1. How would Unicode letters change category detection?
  2. Why is a configurable policy preferable to embedding many enterprise rules in one regular expression?
  3. How would you report every failed rule without leaking the password into logs?

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...