Validate a credit card number (similar to HackerRank "Validating Credit Card Numbers"); write the optimal approach on paper and explain time complexity.
Asked in the Onsite round 1 stage. Candidate says the asked problem was slightly similar to the HackerRank problem. Reported follow-ups: How would you generalize the code for other applications? How would the application work in real time?
Implement def validate_card_number(card_number):. The input is a string containing 13 to 19 digits, optionally separated by consistent single spaces or hyphens. Return True when formatting is valid and the digits satisfy the Luhn checksum; otherwise return False.
card_number is a string.def validate_card_number(card_number):