Wednesday, 1 Dec 2021
Category: subsequence

Given an array vec[] of size N of non-negative integers. The task is to count the number of subsequences with the sum equal to S – 2 where S is the sum of all the elements of the array.Examples:Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA […]

Given an array arr[] of size N and an integer X, the task is to find the length of the longest subsequence such that the prefix sum at every element of the subsequence remains greater than zero.Example:Input: arr[] = {-2, -1, 1, 2, -2}, N = 5Output: 3Explanation: The sequence can be made of elements […]

Given a string S, the task is to find the lexicographically largest subsequence that can be formed using all distinct characters only once from the given string.Examples:Input: S = ababcOutput: bacExplanation:All possible subsequences containing all the characters in S exactly once are {“abc”, “bac”}. The lexicograohically maximum among all the subsequences  is “bac”.Input: S = […]

Given an array arr[] consisting of N positive integers, the task is to find the number of subsequences of length 4 having product of the first three elements equal to the fourth element.Examples:Input: arr[] = {10, 2, 2, 7, 40, 160}Output: 2Explanation:Following are the subsequences of length 4 satisfying the given criteria:{10, 2, 2, 40}, […]

#include using namespace std;  void findIfPossible(int N, string str){    int countG = 0, countF = 0;    for (int i = 0; i < N; i++) {          if (str[i] == 'G')            countG++;        else            countF++;    }      if (2 * countF != countG) {        cout

Given an array arr[] consisting of N positive integers, the task is to check if the product of elements of every subsequence of the given array arr[] is a perfect square or not. If found to be true, then print Yes. Otherwise, print No.Examples:Input: arr[] = {1, 4, 100}Output: YesExplanation:Following are the subsequences of the […]

Maximum count of “010..” subsequences that can be removed from given Binary StringGiven a binary string S consisting of size N, the task is to find the maximum number of binary subsequences of the form “010..” of length at least 2 that can be removed from the given string S.Examples:Input: S = “110011010”Output: 3Explanation:Following are […]

Check if given String can be split only into subsequences ABCGiven a string S of length N where each character of the string is either ‘A‘, ‘B‘ or ‘C‘. The task is to find if is it possible to split the string into subsequences “ABC“. If it is possible to split then print “Yes“. Otherwise, […]

Minimum number of removals required such that no subsequence of length 2 occurs more than onceGiven a string S consisting of N lowercase characters, the task is to modify the given string such that no subsequence of length two repeats in the string by removing minimum number of characters.Examples:Input: S = “abcaadbcd”Output: abcdExplanation: Removing the […]

Maximum number of plates that can be placed from top to bottom in increasing order of sizeGiven a 2D array plates[][] of size N, which each row representing the length and width of a N rectangular plates, the task is to find the maximum number of plates that can be placed on one another. Note: […]