diff --git a/GeeksForGeeks/June/18-6-24/GFG.java b/GeeksForGeeks/June/18-6-24/GFG.java new file mode 100644 index 0000000..855aede --- /dev/null +++ b/GeeksForGeeks/June/18-6-24/GFG.java @@ -0,0 +1,44 @@ +//{ 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) { + int N = Integer.parseInt(read.readLine()); + Solution ob = new Solution(); + int ans = ob.rectanglesInCircle(N); + System.out.println(ans); + } + } +} +// } Driver Code Ends + + +// User function Template for Java + +class Solution { + int rectanglesInCircle(int r) { + // code here + double d = r*2; + int cnt = 0; + double area = 3.14*r*r; + for(int i=1; i<=d; i++) + { + for(int j=1; j<=d; j++) + { + double temp = i*j; + double dia = Math.sqrt(i*i+j*j); + + if (temp<=area && d>=dia) + cnt++; + } + } + + return cnt; + } +}; diff --git a/GeeksForGeeks/June/18-6-24/README.md b/GeeksForGeeks/June/18-6-24/README.md new file mode 100644 index 0000000..1d3ee04 --- /dev/null +++ b/GeeksForGeeks/June/18-6-24/README.md @@ -0,0 +1,2 @@ +Time complexity - O(n^2) +Space complexity - O(1) diff --git a/LeetCode/June/18-6-24/README.md b/LeetCode/June/18-6-24/README.md new file mode 100644 index 0000000..7384c4b --- /dev/null +++ b/LeetCode/June/18-6-24/README.md @@ -0,0 +1,2 @@ +Time complexity - O(n) +Space complexity - O(n) diff --git a/LeetCode/June/18-6-24/Solution.java b/LeetCode/June/18-6-24/Solution.java new file mode 100644 index 0000000..49bff8f --- /dev/null +++ b/LeetCode/June/18-6-24/Solution.java @@ -0,0 +1,28 @@ +class Solution +{ + public int maxProfitAssignment(int[] difficulty, int[] profit, int[] worker) + { + int maxDifficulty = 0; + for (int d : difficulty) + maxDifficulty = Math.max(maxDifficulty, d); + + int[] maxProfitUpToDifficulty = new int[maxDifficulty + 1]; + for (int i = 0; i < difficulty.length; i++) + maxProfitUpToDifficulty[difficulty[i]] = Math.max(maxProfitUpToDifficulty[difficulty[i]], profit[i]); + + for (int i = 1; i <= maxDifficulty; i++) + maxProfitUpToDifficulty[i] = Math.max(maxProfitUpToDifficulty[i], maxProfitUpToDifficulty[i - 1]); + + int totalProfit = 0; + for (int ability : worker) + { + if (ability > maxDifficulty) + totalProfit += maxProfitUpToDifficulty[maxDifficulty]; + else + totalProfit += maxProfitUpToDifficulty[ability]; + } + + return totalProfit; + } + +}