Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Python: Prime, Two-Sum, Inheritance

HardPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Python: Prime, Two-Sum, Inheritance. Start with the requirements on the right.

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.

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):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output