Skip to content

Commit

Permalink
Added codes for 25 March
Browse files Browse the repository at this point in the history
  • Loading branch information
Tanmay-312 committed Mar 25, 2024
1 parent 8f76ae0 commit 72aa869
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 0 deletions.
52 changes: 52 additions & 0 deletions GeeksForGeeks/March/25-3-24/GFG.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
//{ 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();
ArrayList<String> result = ob.NBitBinary(n);
for(String value : result){
System.out.print(value + " ");
}
System.out.println();
}
}
}
// } Driver Code Ends


//User function Template for Java

class Solution {
ArrayList<String> NBitBinary(int N)
{
// code here
ArrayList<String> li = new ArrayList<>();
solve("",0,0,N,li);
return li;
}

void solve(String str,int oneC,int zero,int N,ArrayList<String> li)
{
if(str.length()==N)
{
li.add(str);
return;
}

solve(str+"1", oneC+1,zero,N,li);

if(zero < oneC)
{
solve(str+"0",oneC,zero+1,N,li);
}
}
}
2 changes: 2 additions & 0 deletions GeeksForGeeks/March/25-3-24/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Time complexity - O(2^n)
Space complexity - O(2^n)
2 changes: 2 additions & 0 deletions LeetCode/March/25-3-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)
17 changes: 17 additions & 0 deletions LeetCode/March/25-3-24/Solution.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Solution
{
public List<Integer> findDuplicates(int[] nums)
{
List<Integer> ans = new ArrayList<>();

for (int num : nums)
{
nums[Math.abs(num) - 1] *= -1;

if (nums[Math.abs(num) - 1] > 0)
ans.add(Math.abs(num));
}

return ans;
}
}

0 comments on commit 72aa869

Please sign in to comment.