Dsa
Greedy
Hard
Climbing Stairs with Minimum Steps
You are climbing a staircase that has N steps. Each step can only be reached from one of the previous two steps, but you can skip to any previous step if your previous step was not high enough. You want to reach the top with the minimum number of steps. Write a program that calculates the minimum number of steps required to reach the top of the stairs. You will read N (the total number of steps) followed by a list of heights for each step. Output the minimum number of steps needed to reach the top.
Input Format:
The first line contains an integer N (1 <= N <= 1000) - the total number of stairs.
The second line contains N space-separated integers representing the heights of each stair.
Output Format:
Print a single integer representing the minimum number of steps required to reach the top.
Example:
Input:
5
1 2 3 4 5
Output:
3
Key concepts
greedydynamic programmingarrays
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now