# Prime-number coding interview question | Aced

Aced (formerly Exponent) publishes a public search API over its indexed pages; the guide is at https://www.aced.io/agents/agent-access.

Source: https://www.aced.io/questions/3629/prime-numbers
Source observed: 2026-11-05T00:06:02.400Z
Last checked: 2026-11-05T00:06:02.4+00:00
Indexed: 2026-11-06T19:27:58.368+00:00

---

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

**Difficulty:** Medium  
**Category:** [Data Structures & Algorithms](https://www.aced.io/questions?type=algorithms) · [Coding](https://www.aced.io/questions?type=coding)

We provide this coding-practice question for candidates preparing for technical interviews. It asks you to implement `find_primes(n)`, returning every prime number less than or equal to `n`.

## Prompt

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]
```

The question includes an editor with **Question**, **Solution**, and **Community** tabs, plus selectable hints and challenges. The available practice workspace includes **Editor**, **Share**, **Output**, **Test Results**, and **Console** panels. We invite you to [sign up to run code](https://www.aced.io/signup?src=lesson). Detailed company statistics for this question are available through [Upgrade](https://www.aced.io/upgrade?src=questions).

## Interview context

The question is associated with these roles:

- [Machine Learning Engineer](https://www.aced.io/questions?role=ml-engineer)
- [Data Engineer](https://www.aced.io/questions?role=data-engineer)
- [Data Scientist](https://www.aced.io/questions?role=data-science)
- [Software Engineer](https://www.aced.io/questions?role=swe)

It is associated with questions asked at:

- [Apple](https://www.aced.io/questions?company=apple)
- [TikTok](https://www.aced.io/questions?company=tiktok)
- [Adobe](https://www.aced.io/questions?company=adobe)
- [Salesforce](https://www.aced.io/questions?company=salesforce)

The interface also labels the question as having been last asked **2 years ago** and offers a **+15 interviews** detail control. No community answers have been contributed yet.

## Related questions

- [Write a function to simulate 25 coin flips with 50/50 probability. Return the number of heads.](https://www.aced.io/questions/3726/simulate-25-coin-flips-function)
- [Write a function to print 1 to n without using a loop.](https://www.aced.io/questions/4618/print-to-n-no-loop)
- [Given a Directed Acyclic Graph (DAG), write a function to return the length of the longest path.](https://www.aced.io/questions/3434/find-longest-path-in-dag)

## Related courses

### [Machine Learning Engineer Interview Prep](https://www.aced.io/courses/ml-engineer)

![Machine Learning Engineer Interview Prep](https://images.ctfassets.net/x78yjrjc11pq/6UfkHxUyLQVfDHSfLNQtWa/1be1539a65b4f6f15201f5b573c0a578/ML_Engineer_Interview_Prep_Course.jpeg?w=800&h=800&fm=webp&q=75)

We help candidates prepare for machine-learning roles at Meta, Google, Amazon, Apple, Microsoft, Nvidia, and other top companies through mock interviews, frameworks, and advice from senior candidates. The course covers ML system design, core concepts, coding, behavioral interviews, and more.

### [Data Science Interview Prep](https://www.aced.io/courses/data-science)

![Data Science Interview Prep](https://images.ctfassets.net/x78yjrjc11pq/3U4C5C0OkDR0UeGch4AmlE/7ad489430b676a088cb973307fe77884/Data_Science_Interview_Prep_Course.jpeg?w=800&h=800&fm=webp&q=75)

We help candidates prepare for data-science roles at Google, Amazon, Microsoft, Meta, Apple, and other top companies with mock interviews, frameworks, and advice from senior candidates. Practice areas include statistics, experimentation, coding, SQL, machine learning, behavioral interviews, and more.

## About Aced

Aced, formerly Exponent, provides interview courses, coding questions, practice tools, and coaching for technology and related roles. Our available areas include software engineering, system design, data science, machine learning, data engineering, product management, behavioral interviewing, SQL, and more. Explore [all questions](https://www.aced.io/questions) or [all courses](https://www.aced.io/courses?src=nav).

---

[Read this page’s summary](https://www.aced.io/agents/api/public/v1/page-tldr?url=https%3A%2F%2Fwww.aced.io%2Fquestions%2F3629%2Fprime-numbers&trace=t_679ff9ab98f3)

## Ask a follow-up about this page

Need a more specific answer? Ask the exact question you have. It returns a fresh, cited answer from Aced (formerly Exponent)’s knowledge base. No account or API key required.

Open this URL with your own question, URL-encoded. Include your question in q. All research inputs are optional; no account or setup.

`GET https://www.aced.io/agents/agent/faq?q={question}&trace=t_679ff9ab98f3`

[Tool guide and examples](https://www.aced.io/agents/agent-access) · [OpenAPI](https://www.aced.io/agents/api/public/v1/openapi.json) · [Page TLDR form](https://www.aced.io/agents/agent-tools/page-tldr?url=https%3A%2F%2Fwww.aced.io%2Fquestions%2F3629%2Fprime-numbers). Opening a form does not execute a tool.