Code RoomValidate form fields
EasyPrep Room Coding #4822

Validate form fields

CodingAlgorithms & data structuresEntry–Mid~16 min

A checkout form moves focus to an error summary so a screen reader announces every problem at once, and that summary is built from field data alone. Three parallel lists arrive in document order: field_ids, rules and values. A rules entry is a comma separated list with no spaces, and it may be empty. The rules are required, email, digits and minlen:N. Trim a value before testing it. A blank value fails required, and every other rule is skipped on a blank value, because an optional field left alone is not an error. email needs exactly one at sign with text on both sides, digits allows only the characters 0 to 9, and minlen:N needs at least N characters. Report a failing field once, by the first rule it fails in the order that field lists them, as the field id, a vertical bar, then the rule exactly as written. Keep the given field order.

Implement
form_error_summary(field_ids: list[str], rules: list[str], values: list[str]) → list[str]
Examples
in[["full_name","work_email","zip_code"],["required","required,email","digits,minlen:5"],[" ","ada@example.com","1234"]]out["full_name|required","zip_code|minlen:5"]
in[["phone","referral"],["digits","email"],[""," "]]out[]
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

0:00 of about 16 min
InputExpectedGot
[["full_name","work_email","zip_code"],["required","required,email","digits,minlen:5"],[" ","ada@example.com","1234"]]["full_name|required","zip_code|minlen:5"]not run yetsample
[["phone","referral"],["digits","email"],[""," "]][]not run yetsample