Skip to content

Commit

Permalink
Added codes for 21 June
Browse files Browse the repository at this point in the history
  • Loading branch information
Tanmay-312 committed Jun 21, 2024
1 parent 6bcb5bc commit 5f5e7cf
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 0 deletions.
52 changes: 52 additions & 0 deletions GeeksForGeeks/June/21-6-24/GFG.java
Original file line number Diff line number Diff line change
@@ -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";
}
}
2 changes: 2 additions & 0 deletions GeeksForGeeks/June/21-6-24/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Time complexity - O(1)
Space complexity - O(1)
2 changes: 2 additions & 0 deletions LeetCode/June/21-6-24/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Time complexity - O(n)
Space complexity - O(1)
22 changes: 22 additions & 0 deletions LeetCode/June/21-6-24/Solution.java
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit 5f5e7cf

Please sign in to comment.