Java Program for Staircase Problem

Java Program for Staircase Problem

Staircase Problem

TCS organizes a global level coding competition every year in the quest of World’s best coder. This is one of the most prestigious coding competition, in which coders from all around the world participate and show of their coding skills, every year more than 200k students participate in the competition out of which only 1 is get’s the title of world’s best coder and the prize of US$ 10,000. Staircase problem is one of the sample problem of TCS CodeVita Season 9 edition, here we have provided the solution of this problem in Java.

Problem Description

There are n stairs, a person standing at the bottom wants to reach the top. The person can climb either 1 stair or 2 stairs at a time.

  • Count the number of ways, the person can reach the top.

Java Code

import java.util.Scanner;
public class Main {
 
     static int path(int m , int n) {
         if(m==1 || n==1) 
             return 1;
         
         return path(m-1,n)+path(m,n-1);
     }
    public static void main(String[] args) {
     
         System.out.println(path(4,4));
        
    }
 
}
Output
5
8

Staircase Problem in Other Coding Languages

C

To find the solution of Staircase  problem in C Programming language click on the button below:

 

C

C++

To find the solution of Staircase  problem in C++ Programming language click on the button below:

 

C++

Python

To find the solution of Staircase problem in Python Programming language click on the button below:

 

Python