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

Note

You can test your code by connecting to Salesforce, but to save your progress and earn points, you'll need to create an account. Your solutions and achievements will be tracked automatically once you're logged in.

Wally can't hear you

Please sign in to access the AI Assistant

Sign In