Given a positive integer n, return a list of its prime factors in ascending order with repetition. For example, 12 = 2 x 2 x 3, so the result is [2, 2, 3]. For values of n less than or equal to 1, return an empty list.
Examples:
Input: n = 12
Output: [2, 2, 3]
Explanation: 12 = 2 x 2 x 3
Input: n = 7
Output: [7]
Explanation: 7 is itself prime
Input: n = 1
Output: []
Explanation: 1 has no prime factors
Input: n = 100
Output: [2, 2, 5, 5]
Explanation: 100 = 2 x 2 x 5 x 5
Input: n = 30
Output: [2, 3, 5]
Explanation: 30 = 2 x 3 x 5
Apex Code Editor
Welcome to Lightning Challenge!
Create an Account
Sign up to track your progress, earn points, and compete with others. Your solutions will be saved automatically.
Create accountHow It Works
- • Write your solution in the code editor
- • Connect your Salesforce org to test
- • Submit to check if your solution passes
- • Use hints if you get stuck
Contest Alert
🏆 #CodeEveryDay June 2026
Contest runs June 1 - 30. Complete challenges to climb the leaderboard!
Only the 30 daily challenges shown during this contest count toward points. Earlier dailies don't carry over.