diff --git a/GeeksForGeeks/April/24-4-24/GFG.java b/GeeksForGeeks/April/24-4-24/GFG.java new file mode 100644 index 0000000..3b1c15a --- /dev/null +++ b/GeeksForGeeks/April/24-4-24/GFG.java @@ -0,0 +1,62 @@ +//{ Driver Code Starts +//Initial Template for Java + + +import java.io.*; +import java.util.*; + + +// } Driver Code Ends +//User function Template for Java + + +class Solution +{ + public static int ways(int n, int m) + { + // complete the function + int[][] dp = new int[n + 1][m + 1]; + for (int i = 0; i <= n; i++) + { + dp[i][0] = 1; + } + + for (int i = 0; i <= m; i++) + { + dp[0][i] = 1; + } + + for (int i = 1; i <= n; i++) + { + for (int j = 1; j <= m; j++) + { + dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % 1000000007; + } + } + return dp[n][m]; + } +} + +//{ Driver Code Starts. + +// Driver class +class Array { + + // Driver code + public static void main (String[] args) throws IOException{ + // Taking input using buffered reader + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + int testcases = Integer.parseInt(br.readLine()); + // looping through all testcases + while(testcases-- > 0){ + String line = br.readLine(); + String[] elements = line.trim().split("\\s+"); + int x=Integer.parseInt(elements[0]); + int y=Integer.parseInt(elements[1]); + Solution ob = new Solution(); + System.out.println(ob.ways(x,y)); + } + } +} +// } Driver Code Ends diff --git a/GeeksForGeeks/April/24-4-24/README.md b/GeeksForGeeks/April/24-4-24/README.md new file mode 100644 index 0000000..8faf6d9 --- /dev/null +++ b/GeeksForGeeks/April/24-4-24/README.md @@ -0,0 +1,2 @@ +Time complexity - O(n*m) +Space complexity - O(n*m) diff --git a/LeetCode/April/24-4-24/README.md b/LeetCode/April/24-4-24/README.md new file mode 100644 index 0000000..9567f26 --- /dev/null +++ b/LeetCode/April/24-4-24/README.md @@ -0,0 +1,2 @@ +Time complexity - O(n) +Space complexity - O(1) diff --git a/LeetCode/April/24-4-24/Solution.java b/LeetCode/April/24-4-24/Solution.java new file mode 100644 index 0000000..e06c90d --- /dev/null +++ b/LeetCode/April/24-4-24/Solution.java @@ -0,0 +1,22 @@ +class Solution +{ + public int tribonacci(int n) + { + if (n<2) + return n; + + int prev = 0; + int curr = 1; + int next = 1; + + for (int i=3; i<=n; i++) + { + int temp = next; + next = next + curr + prev; + prev = curr; + curr = temp; + } + + return next; + } +}