Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Prime Number Function

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

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

WebMD Medscape content tooling uses numeric revision tokens that may need prime-number validation before processing. Write a function that determines whether a given integer is prime.

A prime number is an integer greater than 1 with exactly two positive divisors: 1 and itself. Return True when n is prime and False otherwise. Your solution should avoid testing every integer up to n when a smaller search is sufficient.

Formal Specification

  • Input: An integer n.
  • Output: A boolean indicating whether n is prime.
  • Do not modify the input.

Constraints

  • 0 <= n <= 10^12
  • Return False for values less than 2
  • The result must be a boolean
  • Target O(sqrt(n)) time complexity
  • Use O(1) additional space

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