-
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
436e6a3
commit 08cccc1
Showing
4 changed files
with
86 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,37 @@ | ||
//{ Driver Code Starts | ||
// Initial Template for Java | ||
|
||
import java.io.*; | ||
import java.util.*; | ||
|
||
class GFG { | ||
public static void main(String args[]) throws IOException { | ||
BufferedReader read = new BufferedReader(new InputStreamReader(System.in)); | ||
int t = Integer.parseInt(read.readLine()); | ||
|
||
while (t-- > 0) { | ||
String arr[] = read.readLine().trim().split("\\s+"); | ||
double perimeter = Double.parseDouble(arr[0]); | ||
double area = Double.parseDouble(arr[1]); | ||
|
||
Solution ob = new Solution(); | ||
double ans = ob.maxVolume(perimeter, area); | ||
System.out.println(String.format("%.2f", ans)); | ||
} | ||
} | ||
} | ||
// } Driver Code Ends | ||
|
||
|
||
// User function Template for Java | ||
|
||
class Solution { | ||
|
||
double maxVolume(double perimeter, double area) { | ||
// code here | ||
double l = (double)(perimeter - Math.sqrt(perimeter*perimeter - 24*area))/12; | ||
double h = perimeter/4 - 2*l; | ||
double volume = l*l*h; | ||
return volume; | ||
} | ||
} |
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*log(max(BloomDay))) | ||
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,45 @@ | ||
class Solution | ||
{ | ||
public int minDays(int[] bloomDay, int m, int k) | ||
{ | ||
int start = 1; | ||
int end = Arrays.stream(bloomDay).max().getAsInt(); | ||
int ans = -1; | ||
|
||
while (start <= end) | ||
{ | ||
int mid = start + (end - start) / 2; | ||
int currLength = 0; | ||
int count = 0; | ||
|
||
for (int i = 0; i < bloomDay.length; i++) | ||
{ | ||
if (bloomDay[i] <= mid) | ||
{ | ||
currLength++; | ||
if (currLength >= k) | ||
{ | ||
currLength = 0; | ||
count++; | ||
} | ||
} | ||
else | ||
{ | ||
currLength = 0; | ||
} | ||
} | ||
|
||
if (count >= m) | ||
{ | ||
ans = mid; | ||
end = mid - 1; | ||
} | ||
else | ||
{ | ||
start = mid + 1; | ||
} | ||
} | ||
|
||
return ans; | ||
} | ||
} |