Skip to content

Commit

Permalink
Added codes for 19 June
Browse files Browse the repository at this point in the history
  • Loading branch information
Tanmay-312 committed Jun 19, 2024
1 parent 436e6a3 commit 08cccc1
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 0 deletions.
37 changes: 37 additions & 0 deletions GeeksForGeeks/June/19-6-24/GFG.java
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;
}
}
2 changes: 2 additions & 0 deletions GeeksForGeeks/June/19-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/19-6-24/README.md
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)
45 changes: 45 additions & 0 deletions LeetCode/June/19-6-24/Solution.java
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;
}
}

0 comments on commit 08cccc1

Please sign in to comment.