-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d0b36ae
commit 927dec7
Showing
4 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Time complexity - O(n) | ||
Space complexity - O(n) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Time complexity - O(n^2) | ||
Space complexity - O(n) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |