Count the distinct ways to climb to the top of a staircase of n steps when you can take either 1 or 2 steps at a time. Return null for null input. There is 1 way to climb 0 or 1 steps.
Examples:
Input: n = 1
Output: 1
Explanation: Only one way, a single 1-step
Input: n = 2
Output: 2
Explanation: Two ways: 1+1 or 2
Input: n = 4
Output: 5
Explanation: 1+1+1+1, 1+1+2, 1+2+1, 2+1+1, 2+2
Input: n = 5
Output: 8
Explanation: The counts follow a Fibonacci-like pattern
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 16–30)Sponsored by FLXBL
Contest runs September 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.