diff --git a/GeeksForGeeks/June/19-6-24/GFG.java b/GeeksForGeeks/June/19-6-24/GFG.java new file mode 100644 index 0000000..5a1406b --- /dev/null +++ b/GeeksForGeeks/June/19-6-24/GFG.java @@ -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; + } +} diff --git a/GeeksForGeeks/June/19-6-24/README.md b/GeeksForGeeks/June/19-6-24/README.md new file mode 100644 index 0000000..b85bed6 --- /dev/null +++ b/GeeksForGeeks/June/19-6-24/README.md @@ -0,0 +1,2 @@ +Time complexity - O(1) +Space complexity - O(1) diff --git a/LeetCode/June/19-6-24/README.md b/LeetCode/June/19-6-24/README.md new file mode 100644 index 0000000..a787f86 --- /dev/null +++ b/LeetCode/June/19-6-24/README.md @@ -0,0 +1,2 @@ +Time complexity - O(n*log(max(BloomDay))) +Space complexity - O(1) diff --git a/LeetCode/June/19-6-24/Solution.java b/LeetCode/June/19-6-24/Solution.java new file mode 100644 index 0000000..eb75b45 --- /dev/null +++ b/LeetCode/June/19-6-24/Solution.java @@ -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; + } +}