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
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess 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
Build my plan
Amicable Pairs Coding Challenge
00:00
5 left

Amicable Pairs Coding Challenge

MediumPython

Problem

Dynata data-quality checks may need to classify mathematical relationships between numeric values. Given two positive integers, determine whether they form an amicable pair.

Two distinct numbers a and b are amicable when the sum of the proper divisors of a equals b, and the sum of the proper divisors of b equals a. A proper divisor is a positive divisor smaller than the number itself.

Your solution must avoid scanning every integer from 1 through n. Use divisor-pair reasoning so that each number can be processed in O(sqrt(n)) time.

Formal Specification

Implement amicable_pair(a, b).

  • Input: Two positive integers a and b.
  • Output: Return True if they form an amicable pair, otherwise return False.
  • The numbers must be distinct. A perfect number paired with itself is not considered an amicable pair.

Constraints

  • 1 <= a, b <= 10^12
  • a and b are positive integers
  • The inputs must be distinct for the result to be True
  • Do not scan every integer from 1 through either input

Function Signature

def amicable_pair(a, b):
Interviewer

Your question is Amicable Pairs Coding Challenge. 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.
CodePython 3
Sign up free to run your codeLog inLn 2
Run your code to see test output here.