From 9b4794d7c54ff63b1c34c8a603e2988f20919f22 Mon Sep 17 00:00:00 2001 From: Tanmay-312 Date: Thu, 13 Jun 2024 11:17:48 +0530 Subject: [PATCH] Added codes for 13 June --- GeeksForGeeks/June/13-6-24/GFG.java | 45 ++++++++++++++++++++++++++++ GeeksForGeeks/June/13-6-24/README.md | 2 ++ LeetCode/June/13-6-24/README.md | 2 ++ LeetCode/June/13-6-24/Solution.java | 15 ++++++++++ 4 files changed, 64 insertions(+) create mode 100644 GeeksForGeeks/June/13-6-24/GFG.java create mode 100644 GeeksForGeeks/June/13-6-24/README.md create mode 100644 LeetCode/June/13-6-24/README.md create mode 100644 LeetCode/June/13-6-24/Solution.java 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; + } +}