diff --git a/GeeksForGeeks/June/13-6-24/GFG.java b/GeeksForGeeks/June/13-6-24/GFG.java new file mode 100644 index 0000000..8b0e666 --- /dev/null +++ b/GeeksForGeeks/June/13-6-24/GFG.java @@ -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; + } + +} diff --git a/GeeksForGeeks/June/13-6-24/README.md b/GeeksForGeeks/June/13-6-24/README.md new file mode 100644 index 0000000..9567f26 --- /dev/null +++ b/GeeksForGeeks/June/13-6-24/README.md @@ -0,0 +1,2 @@ +Time complexity - O(n) +Space complexity - O(1) diff --git a/LeetCode/June/13-6-24/README.md b/LeetCode/June/13-6-24/README.md new file mode 100644 index 0000000..462165f --- /dev/null +++ b/LeetCode/June/13-6-24/README.md @@ -0,0 +1,2 @@ +Time complexity - O(n*logn) +Space complexity - O(logn) diff --git a/LeetCode/June/13-6-24/Solution.java b/LeetCode/June/13-6-24/Solution.java new file mode 100644 index 0000000..0dc636d --- /dev/null +++ b/LeetCode/June/13-6-24/Solution.java @@ -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; + } +}