Computer scienceProgramming languagesJavaInterview preparationAlgorithms and problem solving techniques

Dynamic programming approach in action

Paid stair climbing

Report a typo

Imagine that there are stairs and a person standing at the bottom. Climbing the stairs, the person can either go to the next step or jump over it. Each stairstep has a price represented by a positive integer number. Write a program that reads a series of integer numbers from the console and prints the minimum sum the person must pay to reach the top of the stairs.

For example, if the stairs prices are 20 30 15 3 1 50 20 then the minimum sum will be 54:

the scheme of climbing the stairs

Sample Input 1:

20 30 15 3 1 50 20

Sample Output 1:

54

Sample Input 2:

1 2 1 2 1

Sample Output 2:

3

Sample Input 3:

30 30 1 1 1 30

Sample Output 3:

61
Write a program in Java 25
import java.util.Scanner;

class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// write your code here

var minSum = 0;

System.out.println(minSum);
}
}

Create a free account to access the full topic