Tag Archives: union-find

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
Given a tree with N vertices and N-1 Edges. Let’s define a function F(a, b) which is equal to the minimum edge weight in the… Read More
Consider a special social network where people are called connected if one person is connected to other with any number of intermediate connections. For example… Read More
Given n expressions of the type x = y and x != y where 1 ≤ x, y ≤ n, the task is to check… Read More
Given a number N(1<=N<=2000)., The task is to find the number strings of size N that can be obtained after using characters from 'a' to… Read More
Given two arrays and with n elements each. The task is to make these two arrays identical i:e, for each , we want to make… Read More
Below are the steps for finding MST using Kruskal’s algorithm 1. Sort all the edges in non-decreasing order of their weight. 2. Pick the smallest… Read More
Given a tree, and the cost of a subtree is defined as |S|*AND(S) where |S| is the size of the subtree and AND(S) is bitwise… Read More