Advertisement
GokulDeep

CountPaths

Jan 7th, 2024
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. package com;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.IOException;
  5. import java.io.InputStreamReader;
  6.  
  7. class CountPaths {
  8.  
  9. public static void main (String[] args) throws IOException {
  10. BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  11. int t = Integer.parseInt(br.readLine().trim());
  12. while(t-->0){
  13. String inputLine[] = br.readLine().trim().split(" ");
  14. int M = Integer.parseInt(inputLine[0]);
  15. int N = Integer.parseInt(inputLine[1]);
  16. Solution ob = new Solution();
  17. System.out.println(ob.numberOfPaths(M, N));
  18. }
  19. }
  20. }
  21.  
  22.  
  23.  
  24.  
  25. // } Driver Code Ends
  26.  
  27.  
  28. class Solution{
  29.  
  30. long numberOfPaths(int M, int N) {
  31. if ((M == 1) || (N == 1)) {
  32. return 1;
  33. }
  34.  
  35. return numberOfPaths(M - 1, N) + numberOfPaths(M, N - 1);
  36. }
  37.  
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement