A Disarium number is a number that equals the sum of its own digits, where each digit is raised to the power of its position counted from the left starting at 1.
For example 89 is a Disarium number because 8 to the power of 1 plus 9 to the power of 2 equals 8 plus 81, which is 89.
Return true when the given number is a Disarium number and false otherwise. Null and negative numbers are never Disarium numbers.
Examples:
Input: number = 89
Output: true
Explanation: 8^1 + 9^2 = 8 + 81 = 89
Input: number = 175
Output: true
Explanation: 1^1 + 7^2 + 5^3 = 1 + 49 + 125 = 175
Input: number = 100
Output: false
Explanation: 1^1 + 0^2 + 0^3 = 1, which is not 100
Input: number = 0
Output: true
Explanation: 0^1 = 0, so zero satisfies the rule
Input: number = -89
Output: false
Explanation: Negative numbers are never Disarium numbers
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
Contest runs November 16 - 30. 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.