Input
raw_inputs = ["@alice_99!", " bob ", "@ab!"]
Output
["alice_99", "bob"]
@alice_99! → trim @ and ! → "alice_99" (8 chars, all valid). " bob " → trim spaces → "bob" (3 chars, valid). @ab! → trim → "ab" (2 chars) — too short, excluded.
User-supplied username strings often arrive with leading or trailing noise — symbols, punctuation, spaces — before the actual username. Your job is to extract the username by trimming the invalid edges, then validate wh...
main.pyEditable starterraw_inputs = ["@alice_99!", " bob ", "@ab!"]
["alice_99", "bob"]
@alice_99! → trim @ and ! → "alice_99" (8 chars, all valid). " bob " → trim spaces → "bob" (3 chars, valid). @ab! → trim → "ab" (2 chars) — too short, excluded.
raw_inputs = ["hello world", "alice-bob", "valid_name"]
["valid_name"]
"hello world" has a space in the middle — not a valid character. "alice-bob" has a hyphen in the middle. "valid_name" passes all checks.
The current approach trims edges and then validates the middle. Could you combine those two phases into a single pass with a different pointer strategy?