Skip to content

Commit

Permalink
Added codes for 18 June
Browse files Browse the repository at this point in the history
  • Loading branch information
Tanmay-312 committed Jun 18, 2024
1 parent ef36cab commit 436e6a3
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 0 deletions.
44 changes: 44 additions & 0 deletions GeeksForGeeks/June/18-6-24/GFG.java
Original file line number Diff line number Diff line change
@@ -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;
}
};
2 changes: 2 additions & 0 deletions GeeksForGeeks/June/18-6-24/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Time complexity - O(n^2)
Space complexity - O(1)
2 changes: 2 additions & 0 deletions LeetCode/June/18-6-24/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Time complexity - O(n)
Space complexity - O(n)
28 changes: 28 additions & 0 deletions LeetCode/June/18-6-24/Solution.java
Original file line number Diff line number Diff line change
@@ -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;
}

}

0 comments on commit 436e6a3

Please sign in to comment.