From 5f5e7cfb468484d75daa7fe22b2ef50372b02491 Mon Sep 17 00:00:00 2001 From: Tanmay-312 Date: Fri, 21 Jun 2024 21:53:50 +0530 Subject: [PATCH] Added codes for 21 June --- GeeksForGeeks/June/21-6-24/GFG.java | 52 ++++++++++++++++++++++++++++ GeeksForGeeks/June/21-6-24/README.md | 2 ++ LeetCode/June/21-6-24/README.md | 2 ++ LeetCode/June/21-6-24/Solution.java | 22 ++++++++++++ 4 files changed, 78 insertions(+) create mode 100644 GeeksForGeeks/June/21-6-24/GFG.java create mode 100644 GeeksForGeeks/June/21-6-24/README.md create mode 100644 LeetCode/June/21-6-24/README.md create mode 100644 LeetCode/June/21-6-24/Solution.java diff --git a/GeeksForGeeks/June/21-6-24/GFG.java b/GeeksForGeeks/June/21-6-24/GFG.java new file mode 100644 index 0000000..a7ac876 --- /dev/null +++ b/GeeksForGeeks/June/21-6-24/GFG.java @@ -0,0 +1,52 @@ +//{ Driver Code Starts +// Initial Template for Java + +import java.io.*; +import java.util.*; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +class GFG { + public static void main(String args[]) throws IOException { + + BufferedReader read = new BufferedReader(new InputStreamReader(System.in)); + + Solution ob = new Solution(); + int t = Integer.parseInt(read.readLine()); + while (t-- > 0) { + String str = read.readLine().trim(); + String ans = ob.compareFrac(str); + System.out.println(ans); + } + } +} + +// } Driver Code Ends + + +// User function Template for Java + +class Solution { + + String compareFrac(String str) { + // Code here + String[] fractions = str.split(", "); + String[] frac1 = fractions[0].split("/"); + String[] frac2 = fractions[1].split("/"); + + int a = Integer.parseInt(frac1[0]); + int b = Integer.parseInt(frac1[1]); + int c = Integer.parseInt(frac2[0]); + int d = Integer.parseInt(frac2[1]); + + double value1 = (double) a / b; + double value2 = (double) c / d; + + if (value1 > value2) + return fractions[0]; + else if (value1 < value2) + return fractions[1]; + else + return "equal"; + } +} diff --git a/GeeksForGeeks/June/21-6-24/README.md b/GeeksForGeeks/June/21-6-24/README.md new file mode 100644 index 0000000..b85bed6 --- /dev/null +++ b/GeeksForGeeks/June/21-6-24/README.md @@ -0,0 +1,2 @@ +Time complexity - O(1) +Space complexity - O(1) diff --git a/LeetCode/June/21-6-24/README.md b/LeetCode/June/21-6-24/README.md new file mode 100644 index 0000000..9567f26 --- /dev/null +++ b/LeetCode/June/21-6-24/README.md @@ -0,0 +1,2 @@ +Time complexity - O(n) +Space complexity - O(1) diff --git a/LeetCode/June/21-6-24/Solution.java b/LeetCode/June/21-6-24/Solution.java new file mode 100644 index 0000000..84c79e4 --- /dev/null +++ b/LeetCode/June/21-6-24/Solution.java @@ -0,0 +1,22 @@ +class Solution { + public int maxSatisfied(int[] customers, int[] grumpy, int minutes) { + int satisfied = 0; + int madeSatisfied = 0; + int windowSatisfied = 0; + + for (int i = 0; i < customers.length; ++i) + { + if (grumpy[i] == 0) + satisfied += customers[i]; + else + windowSatisfied += customers[i]; + + if (i >= minutes && grumpy[i - minutes] == 1) + windowSatisfied -= customers[i - minutes]; + + madeSatisfied = Math.max(madeSatisfied, windowSatisfied); + } + + return satisfied + madeSatisfied; + } +}