Prime Numbers in Interval Problem Statement

You are provided with a positive integer N. Your task is to return all the prime numbers that are less than or equal to N.

Input:

The input consists of an integer 'T' representing the number of test cases. Each test case contains one integer 'N'.

Output:

For each test case, return a list of prime numbers less than or equal to 'N' in ascending order.

Example:

Input:
3
10
5
20
Output:
[2, 3, 5, 7]
[2, 3, 5]
[2, 3, 5, 7, 11, 13, 17, 19]
Note:
  • A prime number is a number greater than 1 that has no factors other than 1 and itself.
  • 1 is not considered a prime number.
  • No need to print the output; just implement the function to return the desired output.

Constraints:

  • 1 <= T <= 100
  • 2 <= N <= 5000

Time Limit: 1 second

AnswerBot
4mo

Return all prime numbers less than or equal to a given positive integer N.

  • Create a function that takes an integer N as input

  • Iterate from 2 to N and check if each number is prime

  • Return a list of prime ...read more

Help your peers!
Select
Add answer anonymously...

Top Business Analyst Interview Questions Asked at UnitedHealth

Q. Estimate the percentage of smokers in the institute.
Q. There are 20 blue balls and 13 red balls in a container. You randomly pick 2 bal...read more
Q. How many Facebook users are there in the world?
Business Analyst Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits