From 08cccc131c8127602d3e0313da4f0e0b42ebe864 Mon Sep 17 00:00:00 2001 From: Tanmay-312 Date: Wed, 19 Jun 2024 20:20:17 +0530 Subject: [PATCH] Added codes for 19 June --- GeeksForGeeks/June/19-6-24/GFG.java | 37 +++++++++++++++++++++++ GeeksForGeeks/June/19-6-24/README.md | 2 ++ LeetCode/June/19-6-24/README.md | 2 ++ LeetCode/June/19-6-24/Solution.java | 45 ++++++++++++++++++++++++++++ 4 files changed, 86 insertions(+) create mode 100644 GeeksForGeeks/June/19-6-24/GFG.java create mode 100644 GeeksForGeeks/June/19-6-24/README.md create mode 100644 LeetCode/June/19-6-24/README.md create mode 100644 LeetCode/June/19-6-24/Solution.java 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; + } +}