If you had to build a system where a user inputs a credit card number, detect which provider it belongs to based on given credit card number ranges.
Asked in the Live DSA round stage. It was the second DSA question, related to using TreeMap in Java, and was solved verbally.
Implement classify_provider(card_number, ranges). card_number is a digit string. ranges is a list of [start, end, provider] entries sorted by start, with non-overlapping inclusive ranges. Return the matching provider, or "Unknown" if no range contains the number.
Examples:
"4111111111111111" with Visa and Mastercard ranges returns "Visa"."6011111111111117" returns "Unknown" when it matches no range.Constraints: Card numbers contain 1 to 19 digits; 1 <= len(ranges) <= 1000.
def classify_provider(card_number, ranges):