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
Python: Prime, Two-Sum, Inheritance
00:00
5 left

Python: Prime, Two-Sum, Inheritance

HardPython

Problem

Ford Hospital and Research Center needs a reusable Python component for screening integer batches. Implement one function that identifies prime values, finds two distinct input positions whose values sum to a target, and demonstrates object-oriented design through inheritance and a decorator.

Requirements

  1. Implement is_prime(number) logic inside the solution. A prime is an integer greater than 1 with exactly two positive divisors.
  2. For every value in nums, produce a Boolean indicating whether it is prime.
  3. Find the first pair of distinct indices [i, j], with i < j, such that nums[i] + nums[j] == target. Return None if no pair exists. Use a hash map for expected linear time.
  4. Define a parent class ScreeningReport and a child class ClinicalScreeningReport that inherits from it. The child must override a formatting method.
  5. Define and use a decorator that marks the formatted report as audited. The decorator must not change the method's returned text.
  6. Return a dictionary with keys prime_flags, pair, and report. The report must be the string produced by the child class and include the word AUDITED.

Formal Specification

Input is nums, a list of integers, and target, an integer. Output is a dictionary containing prime_flags as a Boolean list, pair as a two-element index list or None, and report as a string.

Constraints

  • 1 <= len(nums) <= 100,000
  • -10^9 <= nums[i] <= 10^9
  • -10^9 <= target <= 10^9
  • Return the first valid pair encountered from left to right
  • Duplicate values may appear

Function Signature

def screen_numbers(nums, target):
Interviewer

Your question is Python: Prime, Two-Sum, Inheritance. 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.