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!

How 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 September 2026 (Sep 1–15)Sponsored by FLXBL

Contest runs September 1 - 15. Complete challenges to climb the leaderboard!

1st & 2nd: Salesforce certification exam voucher see all prizes

Only the 15 daily challenges shown during this contest count toward points. Earlier dailies don't carry over.

Wally can't hear you

Please sign in to access the AI Assistant

Sign In