Skip to content

Commit

Permalink
Added for 4 Jan
Browse files Browse the repository at this point in the history
  • Loading branch information
Tanmay-312 committed Jan 4, 2024
1 parent 65ce7ed commit 2dff809
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 0 deletions.
56 changes: 56 additions & 0 deletions GeeksForGeeks/4-1-24/GFG.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
//{ 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());

String S[] = read.readLine().split(" ");

int[] arr = new int[N];

for(int i=0 ; i<N ; i++)
arr[i] = Integer.parseInt(S[i]);

Solution ob = new Solution();
System.out.println(ob.singleElement(arr,N));
}
}
}
// } Driver Code Ends


//User function Template for Java

class Solution
{
static int singleElement(int[] arr , int n)
{
// code here
int result = 0;
int x, sum;

for (int i = 0; i < 32; i++)
{
sum = 0;
x = (1 << i);
for (int j = 0; j < n; j++)
{
if ((arr[j] & x) != 0)
sum++;
}

if ((sum % 3) != 0)
result |= x;
}

return result;
}
}
2 changes: 2 additions & 0 deletions GeeksForGeeks/4-1-24/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Time complexity - O(n)
Space complexity - O(1)
2 changes: 2 additions & 0 deletions LeetCode/4-1-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)
21 changes: 21 additions & 0 deletions LeetCode/4-1-24/Solution.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class Solution
{
public int minOperations(int[] nums)
{
int ans = 0;
Map<Integer, Integer> count = new HashMap<>();

for (final int num : nums)
count.merge(num, 1, Integer::sum);

for (final int freq : count.values())
{
if (freq == 1)
return -1;

ans += (freq + 2) / 3;
}

return ans;
}
}

0 comments on commit 2dff809

Please sign in to comment.