Skip to content

Commit

Permalink
Added codes for 24 April
Browse files Browse the repository at this point in the history
  • Loading branch information
Tanmay-312 committed Apr 24, 2024
1 parent b4e33c8 commit bd6f5f2
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 0 deletions.
62 changes: 62 additions & 0 deletions GeeksForGeeks/April/24-4-24/GFG.java
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions GeeksForGeeks/April/24-4-24/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Time complexity - O(n*m)
Space complexity - O(n*m)
2 changes: 2 additions & 0 deletions LeetCode/April/24-4-24/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Time complexity - O(n)
Space complexity - O(1)
22 changes: 22 additions & 0 deletions LeetCode/April/24-4-24/Solution.java
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit bd6f5f2

Please sign in to comment.