Design, and more importantly refactor, a PasswordChecker for a signup flow.
The product has three password requirements today:
8 characters;0 to 9; andThe legacy starter was built for an imagined future where administrators could assemble password rules at runtime. It includes a rule interface and speculative uppercase and symbol checks. Those features were never requested, and they now reject passwords the product considers valid.
Refactor the code to the smallest clear design that meets the current requirements:
PasswordChecker() creates a checker.String check(String password) returns the first applicable result in this order:"TOO_SHORT""MISSING_DIGIT""HAS_SPACE""OK"Remove the speculative rules engine rather than extending it with another rule class. YAGNI is about keeping tomorrow's guesses out of today's design.
Input:
Output:
Explanation: Uppercase letters and symbols are allowed, but they are not required. The third password fails the rule that actually exists: no spaces.
Input:
Output:
Explanation: Checks run in a fixed order, so each password produces one useful result.
0 <= password.length <= 40password contains only ASCII characters.100 calls will be made to check.The starter compiles, but it solves a larger, hypothetical problem and enforces rules that do not belong here. Simplify it and add the missing space check.
Full marks when the checker enforces only minimum length, an ASCII digit and no spaces. Lose points heavily for uppercase, symbol, entropy or configurable-rule behavior that no requirement asks for.
Full marks for a small PasswordChecker with direct, readable checks. A private helper for digit detection is fine. Lose points for retaining the rule interface, registry, factory, priorities or runtime configuration.
Full marks when failures follow the required precedence and return the exact status strings. Lose points when speculative rules reject valid passwords, spaces are missed, or the class prints to stdout.
Passing every test is not enough on its own. A submission is accepted only when the design also clears the bar.
| Call | Returns |
|---|---|
| new PasswordChecker() | null |
| check("Abcd123!") | "OK" |
| check("abcd1234") | "OK" |
| check("abcd 123") | "HAS_SPACE" |
Uppercase and symbols are not requirements. A space is rejected even when length and digit checks pass.
Run checks these cases. Submit also runs a larger hidden set.

