Prabhdeep Singh

Prabhdeep Singh

161 Articles Published

Articles by Prabhdeep Singh

Page 12 of 17

Count of N length Strings having S as a Subsequence

Prabhdeep Singh
Prabhdeep Singh
Updated on 24-Aug-2023 319 Views

We are given a string of length S and given an another number n which represents the length of the strings which might contains S as the subsequence. We have to find the number of unique strings of length N which contains S as the subsequence, where a subsequence is the set of characters from the given string which may be all the characters or not and they not need to be continuous. Sample Examples Input string str = "xyz" int n = 3 Output 1 Explanation There is only one string of length 3 that contains the ...

Read More

Count of Subsequences of given string X in between strings Y and Z

Prabhdeep Singh
Prabhdeep Singh
Updated on 24-Aug-2023 308 Views

A subsequence is a string that can be achieved from another string by removing some (possibly none or all) from a given string that may not be continuous. We are given a string and have to find the number of subsequences that are greater than equal to the given string Y and less than equal to another given string Z. We will use dynamic programming to solve the problem as brute force will take exponential time. Brute Force Approach The brute forces approach is to find all the subsequences of the given string X and then check if they are ...

Read More

Longest Substring with at most X 0s and Y 1s of given String

Prabhdeep Singh
Prabhdeep Singh
Updated on 24-Aug-2023 364 Views

A substring is the continuous sequence of the character from the given string which can be achieved by removing some character from the front and the end of the substring (possibly all or none). We are given a binary string and we have to find the length of the longest substring that contains at most X number zeros and Y number of ones where X and Y are given inputs. Sample Examples Input  string str = "101011"; int x = 1; int y = 2; Output The length of the longest substring with at most X zeroes and ...

Read More

XOR of all substrings of a given Binary String

Prabhdeep Singh
Prabhdeep Singh
Updated on 24-Aug-2023 497 Views

A binary string is a string that contains only two different types of characters in it which are '0' and '1'. Substrings are strings that are formed by deleting some character from the given string from the beginning and from the ending (possibly zero or all). We are given a string and we have to get all the substrings of it and take XOR of it. XOR is a bitwise operator that gives the result − if both the bits are the same then it will return zero otherwise 1. Input  string str = "10101" Output  XOR of all ...

Read More

Minimum cost to delete characters from String A to remove any subsequence as String B

Prabhdeep Singh
Prabhdeep Singh
Updated on 24-Aug-2023 490 Views

We are given two strings string A and string B along with an array that represents the cost to delete the ith character of the given string A. We need to delete some characters of string A (possibly zero or none) with the minimum cost such that no subsequence of A represents string B. We are going to see three approaches to implementing the code that is the recursive approach; the recursive and memoization approach; and tabulation or iterative dp. Example Let's have a look at the following example − Input string a = "xanxd" string b = ...

Read More

Transform string A into B by deleting characters from ends and reinserting at any position

Prabhdeep Singh
Prabhdeep Singh
Updated on 24-Aug-2023 256 Views

Anagram of a string means a string contains exact same characters as another string with the order of characters may vary from the original string, so we called that both strings are anagram of each other. Here we have given the two strings first and second which are anagrams of each other. And our task is to minimize the count of operations to make the first string as second string. An operation is that we can delete an character from the begin or end of an first string and reinserting at any position. Sample Example Input  First: "hello", Second: "ohlle" ...

Read More

Count of possible distinct Binary strings after replacing 11 with 0

Prabhdeep Singh
Prabhdeep Singh
Updated on 24-Aug-2023 210 Views

A binary string is a string that contains only two types of different characters zeroes and ones. We can replace a substring '11' of the given string with another string '0' and we have to find the number of different possible strings we can get from it. We are going to use dynamic programming to get the solution as other methods may take exponential time complexity. Sample Example Input string str = 11010 Output 2 Explanation We can replace the first two numbers with the zero and can get another string 0010 and the second string is the ...

Read More

Minimum characters to be replaced in Ternary string to remove all palindromic substrings for Q queries

Prabhdeep Singh
Prabhdeep Singh
Updated on 26-Jul-2023 269 Views

A palindromic string is a string that is equal to its reverse string. We are given a string that contains ‘0’, ‘1’, and ‘2’ and an array Q of length N and each index of the given array indicates a range in the form of pairs. We have to find the minimum number of characters that are needed to replace in the given range such that none of the palindromic substrings remains in that range. Sample Example Input1: string s: “01001020002”, int Q = {{0, 4}, {2, 5}, {5, 10}}; Output: 1 1 3 Explanation For the range ...

Read More

Maximize given function by selecting equal length substrings from given Binary Strings

Prabhdeep Singh
Prabhdeep Singh
Updated on 26-Jul-2023 338 Views

Two binary strings str1 and str2 of the same length are given and we have to maximize a given function value by choosing the substrings from the given strings of equal length. The given function is such that − fun(str1, str2) = (len(substring))/(2^xor(sub1, sub2)). Here, len(substring) is the length of the first substring while xor(sub1, sub2) is the xor of the given substrings as they are binary strings so it is possible. Sample Examples Input1: string str1 = 10110 & string str2 = 11101 Output: 3 Explanation We can choose a lot of different sets of strings ...

Read More

Minimum number of adjacent swaps to reverse a String

Prabhdeep Singh
Prabhdeep Singh
Updated on 26-Jul-2023 1K+ Views

A string str is given and we can swap only adjacent characters to make the string reverse. We have to find the number of minimum moves required to make the string reverse just by swapping the adjacent characters. We will implement two approaches to find the required solution with the explanation and the implementation of the code. Sample Examples Input1: string str1 = “shkej” Output: 10 Explanation First, we will take the last character to the first position which will take 4 swappings, and then the string will be “jshke”. Then we will move ‘e’ to the second ...

Read More
Showing 111–120 of 161 articles
« Prev 1 10 11 12 13 14 17 Next »
Advertisements