Skip to content

Commit

Permalink
Added codes for 9 May
Browse files Browse the repository at this point in the history
  • Loading branch information
Tanmay-312 committed May 9, 2024
1 parent 137e572 commit ae9ec1b
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 0 deletions.
34 changes: 34 additions & 0 deletions GeeksForGeeks/May/09-5-24/GFG.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//{ Driver Code Starts
// Initial Template for Java

import java.io.*;
import java.lang.*;
import java.math.*;
import java.util.*;

class GFG {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
while (T-- > 0) {
int n = sc.nextInt();
Solution obj = new Solution();
String ans = obj.divisorGame(n) ? "True" : "False";
System.out.println(ans);
}
}
}

// } Driver Code Ends


// User function Template for Java

class Solution {
public static boolean divisorGame(int n) {
// code here
if(n%2==0)
return true;
return false;
}
}
2 changes: 2 additions & 0 deletions GeeksForGeeks/May/09-5-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/May/09-5-24/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Time complexity - O(|sort|)
Space complexity - O(|sort|)
17 changes: 17 additions & 0 deletions LeetCode/May/09-5-24/Solution.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Solution {
public long maximumHappinessSum(int[] happiness, int k)
{
Arrays.sort(happiness);
int i=0, j = happiness.length-1;
long ans=0;

while (i<k)
{
ans += Math.max(0, happiness[j]-i);
i++;
j--;
}

return ans;
}
}

0 comments on commit ae9ec1b

Please sign in to comment.