Code RoomLuhn checksum validation
MediumPrep Room Coding #1557

Luhn checksum validation

CodingSecurityMid–Senior~18 min

Implement the Luhn checksum used to validate credit-card numbers. Given a card `number` as a string (which may contain spaces or dashes as separators), return True if it passes the Luhn check. The algorithm: from the rightmost digit moving left, double every second digit; if a doubled value exceeds 9 subtract 9; sum all resulting digits; the number is valid if the total is divisible by 10. Ignore non-digit separators. An input with no digits is invalid.

Implement
luhn_valid(number: str) → bool
Examples
in["4539148803436467"]outtrue
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 18 min
InputExpectedGot
["4539148803436467"]truenot run yetsample