Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Get started
Card Provider Detection
00:00
5 left

Card Provider Detection

MediumPython

Problem

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.

Constraints

  • card_number contains 1 to 19 decimal digits
  • 1 <= len(ranges) <= 1000
  • Each range is [start, end, provider]
  • start and end are non-negative integers with start <= end
  • ranges are sorted by start and do not overlap
  • provider is a non-empty string

Function Signature

def classify_provider(card_number, ranges):
Interviewer

Your question is Card Provider Detection. Start with the requirements in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
Code
Sign up free to run your codeLog inLn 2
Run your code to see test output here.