-
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
dfe21d1
commit 9b4794d
Showing
4 changed files
with
64 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,45 @@ | ||
//{ Driver Code Starts | ||
//Initial Template for Java | ||
|
||
import java.io.*; | ||
import java.util.*; | ||
class GfG | ||
{ | ||
public static void main(String args[]) | ||
{ | ||
Scanner sc = new Scanner(System.in); | ||
int t = sc.nextInt(); | ||
while(t-->0) | ||
{ | ||
int n = sc.nextInt(); | ||
Solution ob = new Solution(); | ||
System.out.println(ob.padovanSequence(n)); | ||
} | ||
} | ||
} | ||
// } Driver Code Ends | ||
|
||
|
||
//User function Template for Java | ||
|
||
class Solution | ||
{ | ||
int mod = 1000000007; | ||
public int padovanSequence(int n) | ||
{ | ||
//code here. | ||
if (n < 3) | ||
return 1; | ||
|
||
int a=1, b=1, c=1, d=1; | ||
for (int i=3; i<=n; i++) | ||
{ | ||
d = (a + b)%mod; | ||
a = b; | ||
b = c; | ||
c = d; | ||
} | ||
return d; | ||
} | ||
|
||
} |
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(1) |
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*logn) | ||
Space complexity - O(logn) |
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,15 @@ | ||
class Solution | ||
{ | ||
public int minMovesToSeat(int[] seats, int[] students) | ||
{ | ||
int res = 0; | ||
|
||
Arrays.sort(seats); | ||
Arrays.sort(students); | ||
|
||
for (int i = 0; i < seats.length; i++) | ||
res += Math.abs(seats[i] - students[i]); | ||
|
||
return res; | ||
} | ||
} |