Code RoomAllowlist input sanitization
EasyPrep Room Coding #1561

Allowlist input sanitization

CodingSecurityEntry–Mid~10 min

Implement allowlist-based input sanitization. Given a `value` string and an `allowlist` (a list of permitted characters), return a new string containing only the characters of `value` that appear in the allowlist, preserving their original order. Characters not on the allowlist are dropped entirely. This is the safe alternative to denylisting dangerous characters.

Implement
sanitize_input(value: str, allowlist: list[str]) → str
Examples
in["ab<script>12",["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","0","1","2","3","4","5","6","7","8","9"]]out"abscript12"
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 10 min
InputExpectedGot
["ab<script>12",["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","0","1","2","3","4","5","6","7","8","9"]]"abscript12"not run yetsample