Skip to main content
All Questions

Write a function to return all prime numbers up to a given number n.

Medium

Write a function find_primes(n) that returns all prime numbers less than or equal to n.

Examples

Python
find_primes(1) # => [] find_primes(5) # => [2, 3, 5] find_primes(20) # => [2, 3, 5, 7, 11, 13, 17, 19]

Related courses

Course

Machine Learning Engineer Interview Prep

Land your dream machine learning role at Meta, Google, Amazon, Apple, Microsoft, Nvidia, and other top companies. Learn from mock interviews, frameworks, and advice from senior candidates. Explore ML system design, core concepts, coding, behavioral interviews, and more.

Course

Data Science Interview Prep

Land your dream data science role at Google, Amazon, Microsoft, Meta, Apple, and other top companies. Learn from mock interviews, frameworks, and advice from senior candidates. Practice statistics, experimentation, coding, SQL, machine learning, behavioral interviews, and more.