From e7a2c2d95e6e814d985c0715813449ecda99812f Mon Sep 17 00:00:00 2001 From: Tanmay-312 Date: Sun, 21 Apr 2024 07:51:54 +0530 Subject: [PATCH] Added codes for 21 April --- GeeksForGeeks/April/21-4-24/GFG.java | 108 ++++++++++++++++++++++++++ GeeksForGeeks/April/21-4-24/README.md | 2 + LeetCode/April/21-4-24/README.md | 2 + LeetCode/April/21-4-24/Solution.java | 52 +++++++++++++ 4 files changed, 164 insertions(+) create mode 100644 GeeksForGeeks/April/21-4-24/GFG.java create mode 100644 GeeksForGeeks/April/21-4-24/README.md create mode 100644 LeetCode/April/21-4-24/README.md create mode 100644 LeetCode/April/21-4-24/Solution.java 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); + } +}