Skip to content

Commit

Permalink
Added for 5 Jan
Browse files Browse the repository at this point in the history
  • Loading branch information
Tanmay-312 committed Jan 5, 2024
1 parent d0b36ae commit 927dec7
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 0 deletions.
46 changes: 46 additions & 0 deletions GeeksForGeeks/5-1-24/GFG.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//{ Driver Code Starts
//Initial Template for Java

import java.util.*;
import java.lang.*;
import java.io.*;
class GFG
{
public static void main(String[] args) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int T = Integer.parseInt(br.readLine().trim());
while(T-->0)
{
int N = Integer.parseInt(br.readLine().trim());
Solution ob = new Solution();
int ans = ob.TotalWays(N);
System.out.println(ans);
}
}
}

// } Driver Code Ends


//User function Template for Java

class Solution
{
public int TotalWays(int N)
{
// Code here
long fib[] = new long[N+1];
fib[0] = 1;
fib[1] = 1;

for(int i=2;i<N+1;i++)
{
fib[i] = (fib[i-1] + fib[i-2]) % 1000000007;
}

long res = fib[N] + fib[N-1];

return (int)((res*res) % 1000000007);
}
}
2 changes: 2 additions & 0 deletions GeeksForGeeks/5-1-24/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Time complexity - O(n)
Space complexity - O(n)
2 changes: 2 additions & 0 deletions LeetCode/5-1-24/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Time complexity - O(n^2)
Space complexity - O(n)
19 changes: 19 additions & 0 deletions LeetCode/5-1-24/Solution.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class Solution
{
public int lengthOfLIS(int[] nums)
{
if (nums.length == 0)
return 0;

// dp[i] := the length of LIS ending in nums[i]
int[] dp = new int[nums.length];
Arrays.fill(dp, 1);

for (int i = 1; i < nums.length; ++i)
for (int j = 0; j < i; ++j)
if (nums[j] < nums[i])
dp[i] = Math.max(dp[i], dp[j] + 1);

return Arrays.stream(dp).max().getAsInt();
}
}

0 comments on commit 927dec7

Please sign in to comment.