# Tag Archives: Constructive Algorithms (adsbygoogle = window.adsbygoogle || []).push({});

## Split an array into groups of 3 such that X3 is divisible by X2 and X2 is divisible by X1

Given an array A containing N elements (N is divisible by 3), the task is to split the numbers into groups of 3, let the… Read More »

## Find index i such that prefix of S1 and suffix of S2 till i form a palindrome when concatenated

Given two strings A and B of equal lengths, the task is to find an index i such that A[0…i] and B[i+1…n-1] give a palindrome… Read More »

## Check if a string can be converted to another string by replacing vowels and consonants

Given two strings S1 and S2, you are allowed only to change a character at any position to any vowel if it is a vowel… Read More »

## Length of the longest alternating subarray

Given an array of N including positive and negative numbers only. The task is to find the length of the longest alternating (means negative-positive-negative or… Read More »

## Generate a string consisting of characters ‘a’ and ‘b’ that satisfy the given conditions

Given two integers A and B, the task is to generate and print a string str such that: str must only contain the characters ‘a’… Read More »

## Distribute candies in a Binary Tree

Given a binary tree with N nodes, in which each node value represents number of candies present at that node, and there are N candies… Read More »

## Maximize the value of A by replacing some of its digits with digits of B

Given two string A and B which represents two integers, the task is to print the maximized value of A after replacing 0 or more… Read More »

## Maximum count of sub-strings of length K consisting of same characters

Given a string str and an integer k. The task is to count the occurrences of sub-strings of length k that consist of the same… Read More »

## Count of alphabets whose ASCII values can be formed with the digits of N

Given an integer N. You can select any two digits from this number (the digits can be same but their positions should be different) and… Read More »

## Check if array can be divided into two sub-arrays such that their absolute difference is K

Given an array arr[] and an integer K, the task is to find whether the array can be divided into two sub-arrays such that the… Read More »

## Choose atleast two elements from array such that their GCD is 1 and cost is minimum

Given two integer arrays arr[] and cost[] where cost[i] is the cost of choosing arr[i]. The task is to choose a subset with at least… Read More »

## Find the resulting Colour Combination

Given a String of three Colours(G, B, Y) as input, the task is to print the resultant combined colour formed according to the rule given… Read More »

## Count of Numbers such that difference between the number and sum of its digits not less than L

Given a Natural number N and a whole number L, the task is to find the count of numbers, smaller than or equal to N,… Read More »

## Minimize the number of replacements to get a string with same number of ‘a’, ‘b’ and ‘c’ in it

Given a string consisting of only three possible characters ‘a’, ‘b’ or ‘c’. The task is to replace characters of the given string with ‘a’,… Read More »

## Minimum number N such that total set bits of all numbers from 1 to N is at-least X

Given a number X, the task is to find the minimum number N such that total set bits of all numbers from 1 to n… Read More »