Given N vertices numbered from 0 to N – 1 and E edges to form an undirected graph. All the edges should be added in… Read More

# Tag Archives: disjoint-set

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 undirected graph G(V, E) consisting of2 N vertices and M edges, the task is to find the smallest vertex in the connected component… Read More

Given an array of pairs arr[][] of length N, and an array queries[] of length M, and an integer R, where each query contains an… Read More

Given an array arr[](1-based indexing) consisting of N positive integers such that arr[i] denotes the amount of the ith person. Also given are two 2D… Read More

Given an undirected graph G with vertices numbered in the range [0, N] and an array Edges[][] consisting of M edges, the task is to… Read More

Given two arrays A[] and B[] consisting of N positive integers and a matrix List[][] consisting of M pairs of indices, the task is to… 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

Prerequisites: DFS, Trees, DSUGiven a tree with of N nodes from value 1 to N and E edges and array arr[] which denotes number associated… Read More