diff --git a/GeeksForGeeks/April/21-4-24/GFG.java b/GeeksForGeeks/April/21-4-24/GFG.java new file mode 100644 index 0000000..bf041cd --- /dev/null +++ b/GeeksForGeeks/April/21-4-24/GFG.java @@ -0,0 +1,108 @@ +//{ 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()); + int array[] = new int[N]; + Map mp = new HashMap<>(); + + String input_line[] = read.readLine().trim().split(" "); + for(int i=0;ib) + k3++; + else if(original[i]<=b && original[i]>=a) + k2++; + else if(original[i]=a) + kk2++; + + } + + for(int i=k1+k2;ib) + kk3++; + } + Boolean ok = false; + if(k1==kk1 && k2 ==kk2 && k3 == kk3) + ok = true; + + for(int i=0;i rank[j]) + id[j] = i; + else + { + id[i] = j; + ++rank[j]; + } + } + + public int find(int u) + { + return id[u] == u ? u : (id[u] = find(id[u])); + } + + private int[] id; + private int[] rank; +} + +class Solution +{ + public boolean validPath(int n, int[][] edges, int source, int destination) + { + UnionFind uf = new UnionFind(n); + + for (int[] edge : edges) + { + int u = edge[0]; + int v = edge[1]; + uf.unionByRank(u, v); + } + + return uf.find(source) == uf.find(destination); + } +}