Given a non-negative integer n, return its multiplicative persistence: the number of times you must replace the number with the product of its digits until you reach a single-digit number. A number that is already a single digit has a persistence of 0.
Examples:
Input: n = 4
Output: 0
Explanation: 4 is already a single digit
Input: n = 25
Output: 2
Explanation: 25 -> 10 -> 0 takes 2 steps
Input: n = 39
Output: 3
Explanation: 39 -> 27 -> 14 -> 4 takes 3 steps
Input: n = 77
Output: 4
Explanation: 77 -> 49 -> 36 -> 18 -> 8 takes 4 steps
Input: n = 999
Output: 4
Explanation: 999 -> 729 -> 126 -> 12 -> 2 takes 4 steps
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 November 2026 (Nov 1–15)Sponsored by FLXBL
Contest runs November 1 - 15. Complete challenges to climb the leaderboard!
Prizes 1 & 2: Salesforce certification exam voucher — won by random drawing, where every point is a ticket. see all prizes
Only the 15 daily challenges shown during this contest count toward points. Earlier dailies don't carry over.