Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Largest Prime Factor
00:00
5 left

Largest Prime Factor

MediumPython

Problem

How would you find the largest prime factor of a given number?

Given an integer n, implement the function below and return its largest prime factor. The input is an integer n >= 2, and the output must be an integer. Use an approach that avoids testing every value up to n when possible.

Constraints

  • 2 <= n <= 10^12
  • n is a positive integer
  • Return the largest prime factor of n

Function Signature

def largest_prime_factor(n):
Interviewer

Your question is Largest Prime Factor. 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
You need to log in / sign up to run or submit.Ln 2
Run your code to see test output here.