# Tag Archives: union-find

Given a group of N people, each having a unique ID value from 0 to (N – 1) and an array arr[] of M elements… Read More
Given an array arr[] of N strings consisting of lowercase alphabets, the task is to find the number of distinct groups of strings formed after… Read More
Given a disconnected graph G with N vertices and M edges and an array cost[] corresponding to each vertex, the task is to find the… Read More
Given a positive integer N representing the set of integers [1, N] and an array queries[] of length Q of type {L, K}, the task… Read More
Given an array of pairs arr[][] of length N, and an array queries[] of length M, and an integer R, where queries[i] contain an integer… Read More
Given two arrays arr[](1-based indexing) and queries[] consisting of N integers and queries[] contains a permutation of the first N natural numbers, the task is… Read More
Given an array of strings arr[], where each arr[i] is of the form “i==j” or “i!=j”, where i and j are variables representing relationships among… Read More
Given an array, arr[] of size N, an integer P and a 2D array Q[][] consisting of queries of the following type: 1 L R… Read More
Given a binary matrix mat[][] of dimensions NxM such that 1 denotes the island and 0 denotes the water. The task is to find the… Read More
Given a boolean matrix mat[][] consisting of N rows and M columns, initially filled with 0‘s(empty cells), an integer K and queries Q[][] of the… Read More
Given an undirected graph consisting of N vertices and M edges and queries Q[][] of the type {X, Y}, the task is to check if… Read More
Given a graph consisting of N nodes numbered from 0 to N – 1 and M edges in the form of pairs {a, b}, the… Read More
Given an array arr[] containing N intervals, the task is to check that if the intervals can be added or subtracted by X after which… Read More
Given an array arr[][] which contains the edges of a graph to be used to construct an undirected graph G with N nodes, the task… Read More
Given two strings str and str1, the task is to check whether one string can be converted to other by using the following operation:   Convert… Read More