Check if an array can be split into subarrays with GCD exceeding K
Given an array arr[] of N integers and a positive integer K, the task is to check if it is possible to split this array into distinct contiguous subarrays such that the Greatest Common Divisor of all elements of each subarray is greater than K....
read more
Partition array into minimum number of equal length subsets consisting of a single distinct value
Given an array arr[] of size N, the task is to print the minimum count of equal length subsets the array can be partitioned into such that each subset contains only a single distinct element...
read more
Split an array into equal length subsequences consisting of equal elements only
Given an array arr[] of size N, the task is to check if it is possible to split the array arr[] into different subsequences of equal size such that each element of the subsequence are equal. If found to be true, then print “YES”. Otherwise, print “NO”....
read more
Minimize steps required to make two values equal by repeated division by any of their prime factor which is less than M
Given three positive integers M, X, and Y, the task is to find the minimum number of operations required to make X and Y equal such that in each operation divide X or Y by one of its prime factor less than M. If it is not possible to make X and Y equal, then print “-1”....
read more
Rearrange array to make it non-decreasing by swapping pairs having GCD equal to minimum array element
Given an array, arr[] consisting of N positive integers, the task is to make the array non-decreasing by swapping pairs (arr[i], arr[j]) such that i != j (1 ≤ i, j ≤ n) and GCD(arr[i], arr[j]) is equal to the minimum element present in the array....
read more
Smallest string divisible by two given strings
Given two strings S and T of length N and M respectively, the task is to find the smallest string that is divisible by both the two strings. If no such string exists, then print -1....
read more
Count numbers up to C that can be reduced to 0 by adding or subtracting A or B
Given three non-negative integers A, B, and C, the task is to count the numbers in the range [1, C] that can be reduced to 0 by adding or subtracting A or B....
read more
LCM of unique elements present in an array
Given an array arr[] consisting of N positive integers, the task is to find the LCM of all unique elements of the given array. If the array does not contain any unique elements, then print “-1“....
read more
Maximize GCD of an array by increments or decrements by K
Given an array arr[] consisting of N positive integers and a positive integer K, the task is to maximize the GCD of the array arr[] by either increasing or decreasing any array element by K....
read more
Maximum GCD of all nodes in a connected component of an Undirected Graph
Given an undirected graph consisting of V vertices and a 2d array E[][2] denoting edges between pairs of nodes. Given another array arr[] representing values assigned to each node, the task is to find the maximum GCD among the GCD of all connected components in the graph....
read more
Minimize length of an array consisting of difference between all possible pairs
Given an array arr[] of size N, the task is to find the minimum count of elements required to be inserted into the array such that the absolute difference of all possible pairs exists in the array....
read more
GCD of all subarrays of size K
Given an array, arr[] of size N, the task is to print the GCD of all subarrays of size K....
read more