From 816d947c2acc7476c4ddeafcd541d8638dab0d39 Mon Sep 17 00:00:00 2001 From: Tanmay-312 Date: Sat, 16 Mar 2024 08:39:56 +0530 Subject: [PATCH] Added files for 16 March --- .github/workflows/jekyll-gh-pages.yml | 102 +++++++++--------- GeeksForGeeks/February/17-2-24/GFG.java | 116 ++++++++++---------- GeeksForGeeks/February/17-2-24/README.md | 4 +- GeeksForGeeks/January/1-1-24/GFG.java | 128 +++++++++++------------ GeeksForGeeks/January/1-1-24/README.md | 4 +- GeeksForGeeks/January/2-1-24/GFG.java | 56 +++++----- GeeksForGeeks/January/2-1-24/README.md | 4 +- GeeksForGeeks/March/16-3-24/GFG.java | 125 ++++++++++++++++++++++ GeeksForGeeks/March/16-3-24/README.md | 2 + GeeksForGeeks/README.md | 2 +- LeetCode/January/1-1-24/README.md | 4 +- LeetCode/January/1-1-24/Solution.java | 30 +++--- LeetCode/January/2-1-24/README.md | 4 +- LeetCode/January/2-1-24/Solution.java | 36 +++---- LeetCode/March/16-3-24/README.md | 2 + LeetCode/March/16-3-24/Solution.java | 22 ++++ LeetCode/README.md | 2 +- README.md | 6 +- 18 files changed, 400 insertions(+), 249 deletions(-) create mode 100644 GeeksForGeeks/March/16-3-24/GFG.java create mode 100644 GeeksForGeeks/March/16-3-24/README.md create mode 100644 LeetCode/March/16-3-24/README.md create mode 100644 LeetCode/March/16-3-24/Solution.java diff --git a/.github/workflows/jekyll-gh-pages.yml b/.github/workflows/jekyll-gh-pages.yml index 9cb771a..c4e1703 100644 --- a/.github/workflows/jekyll-gh-pages.yml +++ b/.github/workflows/jekyll-gh-pages.yml @@ -1,51 +1,51 @@ -# Sample workflow for building and deploying a Jekyll site to GitHub Pages -name: Deploy Jekyll with GitHub Pages dependencies preinstalled - -on: - # Runs on pushes targeting the default branch - push: - branches: ["main"] - - # Allows you to run this workflow manually from the Actions tab - workflow_dispatch: - -# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages -permissions: - contents: read - pages: write - id-token: write - -# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. -# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. -concurrency: - group: "pages" - cancel-in-progress: false - -jobs: - # Build job - build: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - - name: Setup Pages - uses: actions/configure-pages@v4 - - name: Build with Jekyll - uses: actions/jekyll-build-pages@v1 - with: - source: ./ - destination: ./_site - - name: Upload artifact - uses: actions/upload-pages-artifact@v3 - - # Deployment job - deploy: - environment: - name: github-pages - url: ${{ steps.deployment.outputs.page_url }} - runs-on: ubuntu-latest - needs: build - steps: - - name: Deploy to GitHub Pages - id: deployment - uses: actions/deploy-pages@v4 +# Sample workflow for building and deploying a Jekyll site to GitHub Pages +name: Deploy Jekyll with GitHub Pages dependencies preinstalled + +on: + # Runs on pushes targeting the default branch + push: + branches: ["main"] + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages +permissions: + contents: read + pages: write + id-token: write + +# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. +# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. +concurrency: + group: "pages" + cancel-in-progress: false + +jobs: + # Build job + build: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Setup Pages + uses: actions/configure-pages@v4 + - name: Build with Jekyll + uses: actions/jekyll-build-pages@v1 + with: + source: ./ + destination: ./_site + - name: Upload artifact + uses: actions/upload-pages-artifact@v3 + + # Deployment job + deploy: + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + runs-on: ubuntu-latest + needs: build + steps: + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v4 diff --git a/GeeksForGeeks/February/17-2-24/GFG.java b/GeeksForGeeks/February/17-2-24/GFG.java index 93af924..1e5710e 100644 --- a/GeeksForGeeks/February/17-2-24/GFG.java +++ b/GeeksForGeeks/February/17-2-24/GFG.java @@ -1,58 +1,58 @@ -//{ 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()); // Inputting the testcases - while(t-->0) - { - long n = Long.parseLong(br.readLine().trim()); - long a[] = new long[(int)(n)]; - // long getAnswer[] = new long[(int)(n)]; - String inputLine[] = br.readLine().trim().split(" "); - for (int i = 0; i < n; i++) { - a[i] = Long.parseLong(inputLine[i]); - } - - Solution obj = new Solution(); - System.out.println(obj.countSub(a, n) ? 1:0); - - } - } -} - - -// } Driver Code Ends - - -//User function Template for Java - - -class Solution -{ - public boolean countSub(long arr[], long n) - { - // Your code goes here - for (int i = 0; i <= (n - 2) / 2; i++) - { - if (arr[2 * i + 1] > arr[i]) - { - return false; - } - - if (2 * i + 2 < n && arr[2 * i + 2] > arr[i]) - { - return false; - } - } - return true; - } -} +//{ 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()); // Inputting the testcases + while(t-->0) + { + long n = Long.parseLong(br.readLine().trim()); + long a[] = new long[(int)(n)]; + // long getAnswer[] = new long[(int)(n)]; + String inputLine[] = br.readLine().trim().split(" "); + for (int i = 0; i < n; i++) { + a[i] = Long.parseLong(inputLine[i]); + } + + Solution obj = new Solution(); + System.out.println(obj.countSub(a, n) ? 1:0); + + } + } +} + + +// } Driver Code Ends + + +//User function Template for Java + + +class Solution +{ + public boolean countSub(long arr[], long n) + { + // Your code goes here + for (int i = 0; i <= (n - 2) / 2; i++) + { + if (arr[2 * i + 1] > arr[i]) + { + return false; + } + + if (2 * i + 2 < n && arr[2 * i + 2] > arr[i]) + { + return false; + } + } + return true; + } +} diff --git a/GeeksForGeeks/February/17-2-24/README.md b/GeeksForGeeks/February/17-2-24/README.md index 9567f26..90dcc1d 100644 --- a/GeeksForGeeks/February/17-2-24/README.md +++ b/GeeksForGeeks/February/17-2-24/README.md @@ -1,2 +1,2 @@ -Time complexity - O(n) -Space complexity - O(1) +Time complexity - O(n) +Space complexity - O(1) diff --git a/GeeksForGeeks/January/1-1-24/GFG.java b/GeeksForGeeks/January/1-1-24/GFG.java index f7ec221..d299c10 100644 --- a/GeeksForGeeks/January/1-1-24/GFG.java +++ b/GeeksForGeeks/January/1-1-24/GFG.java @@ -1,64 +1,64 @@ -//{ 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) { - String s1 = br.readLine().trim(); - String[] S1 = s1.split(" "); - int n = Integer.parseInt(S1[0]); - int k = Integer.parseInt(S1[1]); - String s2 = br.readLine().trim(); - String[] S2 = s2.split(" "); - int[] nums = new int[n]; - for (int i = 0; i < n; i++) { - nums[i] = Integer.parseInt(S2[i]); - } - Solution ob = new Solution(); - boolean ans = ob.canPair(nums, k); - if (ans) - System.out.println("True"); - else - System.out.println("False"); - } - } -} - -// } Driver Code Ends - - -// User function Template for Java - -class Solution -{ - public boolean canPair(int[] nums, int k) - { - // Code here - int[] dp = new int[k]; - for(int a : nums) - { - int t = a % k; - if(t<0) - t += k; - - dp[t]++; - } - - if(dp[0] % 2 != 0) - return false; - - for(int i=1; i<=k/2; i++) - { - if(dp[k-i] != dp[i]) - return false; - } - - return true; - } -} +//{ 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) { + String s1 = br.readLine().trim(); + String[] S1 = s1.split(" "); + int n = Integer.parseInt(S1[0]); + int k = Integer.parseInt(S1[1]); + String s2 = br.readLine().trim(); + String[] S2 = s2.split(" "); + int[] nums = new int[n]; + for (int i = 0; i < n; i++) { + nums[i] = Integer.parseInt(S2[i]); + } + Solution ob = new Solution(); + boolean ans = ob.canPair(nums, k); + if (ans) + System.out.println("True"); + else + System.out.println("False"); + } + } +} + +// } Driver Code Ends + + +// User function Template for Java + +class Solution +{ + public boolean canPair(int[] nums, int k) + { + // Code here + int[] dp = new int[k]; + for(int a : nums) + { + int t = a % k; + if(t<0) + t += k; + + dp[t]++; + } + + if(dp[0] % 2 != 0) + return false; + + for(int i=1; i<=k/2; i++) + { + if(dp[k-i] != dp[i]) + return false; + } + + return true; + } +} diff --git a/GeeksForGeeks/January/1-1-24/README.md b/GeeksForGeeks/January/1-1-24/README.md index f981158..b239e05 100644 --- a/GeeksForGeeks/January/1-1-24/README.md +++ b/GeeksForGeeks/January/1-1-24/README.md @@ -1,2 +1,2 @@ -Time Complexity - O(n) -Space Complexity - O(k) +Time Complexity - O(n) +Space Complexity - O(k) diff --git a/GeeksForGeeks/January/2-1-24/GFG.java b/GeeksForGeeks/January/2-1-24/GFG.java index bbf5f2b..c2b69c6 100644 --- a/GeeksForGeeks/January/2-1-24/GFG.java +++ b/GeeksForGeeks/January/2-1-24/GFG.java @@ -1,28 +1,28 @@ -class Solution { - - public long maxSumWithK(long a[], long n, long k) - { - long maxi = Long.MIN_VALUE, sum = 0, prevSum = 0; - int j = 0; - - for(int i = 0; i < k; i++) - sum += a[i]; - - maxi = Math.max(maxi, sum); - for(int i = (int) k; i < n; i++) - { - sum += a[i]; - prevSum += a[j++]; - maxi = Math.max(maxi, sum); - - if(prevSum < 0) - { - sum -= prevSum; - maxi = Math.max(maxi, sum); - prevSum = 0; - } - } - - return maxi; - } -} +class Solution { + + public long maxSumWithK(long a[], long n, long k) + { + long maxi = Long.MIN_VALUE, sum = 0, prevSum = 0; + int j = 0; + + for(int i = 0; i < k; i++) + sum += a[i]; + + maxi = Math.max(maxi, sum); + for(int i = (int) k; i < n; i++) + { + sum += a[i]; + prevSum += a[j++]; + maxi = Math.max(maxi, sum); + + if(prevSum < 0) + { + sum -= prevSum; + maxi = Math.max(maxi, sum); + prevSum = 0; + } + } + + return maxi; + } +} diff --git a/GeeksForGeeks/January/2-1-24/README.md b/GeeksForGeeks/January/2-1-24/README.md index 9567f26..90dcc1d 100644 --- a/GeeksForGeeks/January/2-1-24/README.md +++ b/GeeksForGeeks/January/2-1-24/README.md @@ -1,2 +1,2 @@ -Time complexity - O(n) -Space complexity - O(1) +Time complexity - O(n) +Space complexity - O(1) diff --git a/GeeksForGeeks/March/16-3-24/GFG.java b/GeeksForGeeks/March/16-3-24/GFG.java new file mode 100644 index 0000000..c4f75b4 --- /dev/null +++ b/GeeksForGeeks/March/16-3-24/GFG.java @@ -0,0 +1,125 @@ +//{ Driver Code Starts +import java.util.*; + +class Node +{ + int data ; + Node next; + Node(int d) + { + data = d; + next = null; + } +} + +class Delete_Node +{ + Node head; + Node tail; + + void printList(Node head) + { + Node tnode = head; + while(tnode != null) + { + System.out.print(tnode.data+ " "); + tnode = tnode.next; + } + System.out.println(); + } + + void addToTheLast(Node node) + { + + if(head == null) + { + head = node; + tail = node; + } + else + { + tail.next = node; + tail = node; + } + } + + Node search_Node(Node head, int k) + { + Node current = head; + while(current != null) + { + if(current.data == k) + break; + current = current.next; + } + return current; + } + + public static void main(String args[]) + { + Scanner sc = new Scanner(System.in); + + int t = sc.nextInt(); + while(t>0) + { + int n = sc.nextInt(); + Delete_Node llist = new Delete_Node(); + //int n=Integer.parseInt(br.readLine()); + int a1=sc.nextInt(); + Node head= new Node(a1); + llist.addToTheLast(head); + for (int i = 1; i < n; i++) + { + int a = sc.nextInt(); + llist.addToTheLast(new Node(a)); + } + + int k = sc.nextInt(); + Node del_node = llist.search_Node(llist.head,k); + + Solution g = new Solution(); + if(del_node != null && del_node.next != null) + { + g.deleteNode(del_node); + } + llist.printList(llist.head); + t--; + } + } +} + + + +// } Driver Code Ends + + +/* +class Node +{ + int data ; + Node next; + Node(int d) + { + data = d; + next = null; + } +} +*/ + +//Function to delete a node without any reference to head pointer. +class Solution +{ + void deleteNode(Node del_node) + { + // Your code here + if(del_node == null) + return; + else + if(del_node.next == null) + return; + + del_node.data = del_node.next.data; + + del_node.next = del_node.next.next; + } +} diff --git a/GeeksForGeeks/March/16-3-24/README.md b/GeeksForGeeks/March/16-3-24/README.md new file mode 100644 index 0000000..204234a --- /dev/null +++ b/GeeksForGeeks/March/16-3-24/README.md @@ -0,0 +1,2 @@ +Time complexity - O(1) +space complexity = O(1) diff --git a/GeeksForGeeks/README.md b/GeeksForGeeks/README.md index ca2b968..3d1ea9c 100644 --- a/GeeksForGeeks/README.md +++ b/GeeksForGeeks/README.md @@ -1 +1 @@ -This Folder contains daily problem's solution for GeeksForGeeks. +This Folder contains daily problem's solution for GeeksForGeeks. diff --git a/LeetCode/January/1-1-24/README.md b/LeetCode/January/1-1-24/README.md index b5eb53f..5d54c1c 100644 --- a/LeetCode/January/1-1-24/README.md +++ b/LeetCode/January/1-1-24/README.md @@ -1,2 +1,2 @@ -Time Complexity - O(max (glogg, slogs)) -Space complexity - O(1) +Time Complexity - O(max (glogg, slogs)) +Space complexity - O(1) diff --git a/LeetCode/January/1-1-24/Solution.java b/LeetCode/January/1-1-24/Solution.java index 1db34dd..fca2b44 100644 --- a/LeetCode/January/1-1-24/Solution.java +++ b/LeetCode/January/1-1-24/Solution.java @@ -1,15 +1,15 @@ -class Solution -{ - public int findContentChildren(int[] g, int[] s) - { - Arrays.sort(g); - Arrays.sort(s); - - int i = 0; - for (int j = 0; i < g.length && j < s.length; ++j) - if (g[i] <= s[j]) - ++i; - - return i; - } -} +class Solution +{ + public int findContentChildren(int[] g, int[] s) + { + Arrays.sort(g); + Arrays.sort(s); + + int i = 0; + for (int j = 0; i < g.length && j < s.length; ++j) + if (g[i] <= s[j]) + ++i; + + return i; + } +} diff --git a/LeetCode/January/2-1-24/README.md b/LeetCode/January/2-1-24/README.md index 7384c4b..4e460ad 100644 --- a/LeetCode/January/2-1-24/README.md +++ b/LeetCode/January/2-1-24/README.md @@ -1,2 +1,2 @@ -Time complexity - O(n) -Space complexity - O(n) +Time complexity - O(n) +Space complexity - O(n) diff --git a/LeetCode/January/2-1-24/Solution.java b/LeetCode/January/2-1-24/Solution.java index 33fea2c..df89302 100644 --- a/LeetCode/January/2-1-24/Solution.java +++ b/LeetCode/January/2-1-24/Solution.java @@ -1,18 +1,18 @@ -class Solution -{ - public List> findMatrix(int[] nums) - { - List> ans = new ArrayList<>(); - int[] count = new int[nums.length + 1]; - - for (final int num : nums) - { - if (++count[num] > ans.size()) - ans.add(new ArrayList<>()); - - ans.get(count[num] - 1).add(num); - } - - return ans; - } -} +class Solution +{ + public List> findMatrix(int[] nums) + { + List> ans = new ArrayList<>(); + int[] count = new int[nums.length + 1]; + + for (final int num : nums) + { + if (++count[num] > ans.size()) + ans.add(new ArrayList<>()); + + ans.get(count[num] - 1).add(num); + } + + return ans; + } +} diff --git a/LeetCode/March/16-3-24/README.md b/LeetCode/March/16-3-24/README.md new file mode 100644 index 0000000..7384c4b --- /dev/null +++ b/LeetCode/March/16-3-24/README.md @@ -0,0 +1,2 @@ +Time complexity - O(n) +Space complexity - O(n) diff --git a/LeetCode/March/16-3-24/Solution.java b/LeetCode/March/16-3-24/Solution.java new file mode 100644 index 0000000..8c9a3dc --- /dev/null +++ b/LeetCode/March/16-3-24/Solution.java @@ -0,0 +1,22 @@ +class Solution +{ + public int findMaxLength(int[] nums) + { + int ans = 0; + int prefix = 0; + Map prefixToIndex = new HashMap<>(); + prefixToIndex.put(0, -1); + + for (int i = 0; i < nums.length; ++i) + { + prefix += nums[i] == 1 ? 1 : -1; + + if (prefixToIndex.containsKey(prefix)) + ans = Math.max(ans, i - prefixToIndex.get(prefix)); + else + prefixToIndex.put(prefix, i); + } + + return ans; + } +} diff --git a/LeetCode/README.md b/LeetCode/README.md index 355b2c2..169c546 100644 --- a/LeetCode/README.md +++ b/LeetCode/README.md @@ -1 +1 @@ -This folder is for daily problem's solution of LeetCode. +This folder is for daily problem's solution of LeetCode. diff --git a/README.md b/README.md index be73dfd..490b2cc 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,3 @@ -[My LeetCode profile](https://leetcode.com/tanmay_jain312/) - -[My GeeksForGeeks profile](https://auth.geeksforgeeks.org/user/jain205qv8) +[My LeetCode profile](https://leetcode.com/tanmay_jain312/) + +[My GeeksForGeeks profile](https://auth.geeksforgeeks.org/user/jain205qv8)