Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Prime Number Coding

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

Your question is Prime Number Coding. 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

Within an EVERSANA patient-support workflow, validate whether an integer identifier or generated numeric value is prime. Implement a function that returns whether the given number has exactly two positive divisors: 1 and itself.

Formal Specification

Implement is_prime(n), where n is an integer. Return True if n is prime and False otherwise. Numbers less than 2 are not prime.

Your solution should avoid checking every number up to n. A divisor larger than the square root of n must be paired with a divisor smaller than the square root, so testing through the square root is sufficient.

Constraints

  • -10^12 <= n <= 10^12
  • n is an integer
  • Return either True or False
  • Numbers less than 2 are not prime

Function Signature

def is_prime(n):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output