Skip to content

Commit

Permalink
Added codes for 19 April
Browse files Browse the repository at this point in the history
  • Loading branch information
Tanmay-312 committed Apr 19, 2024
1 parent c08108f commit 3d4c616
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 0 deletions.
83 changes: 83 additions & 0 deletions GeeksForGeeks/April/19-4-24/GFG.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
//{ Driver Code Starts
//Initial Template for Java





import java.io.*;
import java.util.*;


// } Driver Code Ends
//User function Template for Java



class Solution
{
ArrayList<Integer> findMissing(int a[], int b[], int n, int m)
{
Set<Integer> visited = new HashSet<>();
for(int val: b)
{
visited.add(val);
}
ArrayList<Integer> result = new ArrayList<>();
for(int val: a)
{
if(!visited.contains(val))
{
result.add(val);
}
}
return result;
}
}


//{ Driver Code Starts.

// Driver class
class Array {

// Driver code
public static void main(String[] args) throws IOException {
// Taking input using buffered reader
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

int testcases = Integer.parseInt(br.readLine());
// looping through all testcases
while (testcases-- > 0) {
// int n = Integer.parseInt(br.readLine());
String line = br.readLine();
String[] q = line.trim().split("\\s+");
int n =Integer.parseInt(q[0]);
int m =Integer.parseInt(q[1]);
//int y =Integer.parseInt(q[2]);
String line1 = br.readLine();
String[] a1 = line1.trim().split("\\s+");
int a[] = new int[n];
for (int i = 0; i < n; i++) {
a[i] = Integer.parseInt(a1[i]);
}
String line2 = br.readLine();
String[] a2 = line2.trim().split("\\s+");
int b[] = new int[m];
for (int i = 0; i < m; i++) {
b[i] = Integer.parseInt(a2[i]);
}
Solution ob = new Solution();
ArrayList<Integer> ans=ob.findMissing(a,b,n,m);
for (int i = 0; i < ans.size(); i++) {
System.out.print(ans.get(i)+" ");
}
System.out.println();

}
}
}



// } Driver Code Ends
2 changes: 2 additions & 0 deletions GeeksForGeeks/April/19-4-24/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Time complexity - O(n+m)
Space complexity - O(n)
2 changes: 2 additions & 0 deletions LeetCode/April/19-4-24/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Time complexity - O(n*m)
Space complexity - O(n*m)
31 changes: 31 additions & 0 deletions LeetCode/April/19-4-24/Solution.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
class Solution
{
public int numIslands(char[][] grid)
{
int ans = 0;

for (int i = 0; i < grid.length; ++i)
for (int j = 0; j < grid[0].length; ++j)
if (grid[i][j] == '1')
{
dfs(grid, i, j);
++ans;
}

return ans;
}

private void dfs(char[][] grid, int i, int j)
{
if (i < 0 || i == grid.length || j < 0 || j == grid[0].length)
return;
if (grid[i][j] != '1')
return;

grid[i][j] = '2';
dfs(grid, i + 1, j);
dfs(grid, i - 1, j);
dfs(grid, i, j + 1);
dfs(grid, i, j - 1);
}
}

0 comments on commit 3d4c616

Please sign in to comment.