Java Program for Maneuvering a cave (TCS Codevita) | PrepInsta
Maneuvering a Cave Problem
TCS CodeVita organizes a global level coding competition every year, for recruiting some of the best coders from all around the world. This coding competition is one of the prestigious competition in India, as the winner gets a whooping prize money of 10,000 US$. This year it is the 9th season of TCS CodeVita, known as TCS CodeVita 2020 season 9. Maneuvering a cave problem is one of the sample problem of this year competition
Problem Description
The task is to count all the possible paths from top left to bottom right of a m x n matrix with the constraints that from each cell you can either move only to right or down.
Input:
- First line consists of T test cases. First line of every test case consists of N and M, denoting the number of rows and number of columns respectively.
Output:
- Single line output i.e count of all the possible paths from top left to bottom right of a m x n matrix..
Constraints:
- 1<=T<=100
- 1<=N<=100
- 1<=M<=100
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) { Scanner sc = new Scanner(System.in); int a,b,c; System.out.println("Enter test cases : "); c=sc.nextInt(); while(c-- > 0) { System.out.println("Enter number of rows and columns : "); a=sc.nextInt(); b=sc.nextInt(); System.out.println(path(a,b)); } }
Output Enter number of test cases : 2 Enter number of rows and columns : 3 3 6 Enter number of rows and columns : 4 2 4
Maneuvering a Cave Problem in Other Coding Languages
C
To find the solution of Maneuvering a Cave problem in C Programming language click on the button below:
C++
To find the solution of Maneuvering a Cave problem in C++ Programming language click on the button below:
Python
To find the solution of Maneuvering a Cave Problem in Python Programming language click on the button below
Login/Signup to comment