-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6bcb5bc
commit 5f5e7cf
Showing
4 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Time complexity - O(1) | ||
Space complexity - O(1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Time complexity - O(n) | ||
Space complexity - O(1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |