Found 34494 Articles for Programming

Substring with maximum ASCII sum when some ASCII values are redefined

Shubham Vora
Updated on 29-Aug-2023 19:18:50

86 Views

In this problem, we will find the substring of the given string whose character's ASCII value's sum is maximum when we redefine the ASCII values. The naïve approach to solve the problem is to find the sum of all substring's character's ASCII value and get the substring having maximum sum. Another approach to solving the problem is using Kadane's algorithm to find the maximum sub-array sum. Problem statement - We have given a string alpha of size N containing the alphabetical characters. We have also given the chars[], and ASCII[] array of size M, where chars[] contains ... Read More

Split Parenthesis Sequence into maximum valid Substrings

Shubham Vora
Updated on 27-Oct-2023 16:07:31

81 Views

In this problem, we need to split the parenthesis string into valid groups. When all opening brackets have related closing brackets, we can say that the group of parenthesis is valid. Problem Statement We have given a string containing open and closed parentheses. We need to split the string to get the maximum valid parenthesis string. Sample Examples Input: par = "(())()(()())" Output: (()), (), (()()), Explanation Each substring contains the valid parentheses sequence. Input: par = "()()" Output: (), () Explanation We have splited the string into two groups. Input: ... Read More

Python Program for Convert characters of a string to opposite case

Shubham Vora
Updated on 29-Aug-2023 19:14:16

266 Views

In this problem, we will toggle the case of each string character. The easiest way to toggle the case of each string character is using the swapcase() built-in method. Also, we can use the ASCII values of the characters to swap their case. Python also contains isUpper() and isLower() methods to check the character's case and the lower() and upper() method to change the case. Here, we will learn different approaches to solving the problem. Problem statement - We have given a string alpha. We need to toggle the case of string characters. It means converting uppercase ... Read More

Minimize Suffix flip to make Binary String non decreasing

Shubham Vora
Updated on 29-Aug-2023 19:12:16

85 Views

In this problem, we will count the number of minimum operations required to convert string non-decreasing order by flipping the characters of the binary string. We can flip all characters of the substring starting from the \mathrm{p^{th}} index if the character at the pth index is 0 and not matching with character at the previous index, and we can count the minimum flips. Problem statement - We have given a binary string alpha. We need to count the minimum flips required to convert the binary string in increasing order. In one flip, we can select any index p ... Read More

Maximum point to convert string S to T by swapping adjacent characters

Shubham Vora
Updated on 29-Aug-2023 19:09:35

62 Views

In this problem, we will find the maximum points while converting the string S to T according to the conditions in the problem statement. We can traverse the string S and make each character of the string S same as string T's character at the same index by maximum swaps to get maximum points. In the other approach, we will prepare a mathematical formula based on the string's observation to get the answer. Problem statement - We have given a string S and T containing the alphabetical and numeric characters. We need to count the maximum ... Read More

Maximum bitwise OR on of any two Substrings of given Binary String

Shubham Vora
Updated on 29-Aug-2023 18:52:43

68 Views

In this problem, we need to find the maximum OR value of any two substrings of the given strings. The first approach is to find all substrings of the given binary string, take OR value of each string, and print the maximum OR value. The other approach is to take the original string as one substring and take another substring starting from left most zero to maximize the OR value. Problem statement - We have given a binary string alpha. We need to find the maximum OR value of any two substrings of the given binary ... Read More

Count ways to form N Sized Strings with at most two adjacent different pair

Shubham Vora
Updated on 29-Aug-2023 18:38:56

91 Views

In this problem, we will count the number of binary strings of size N, containing at most 2 adjacent distinct pair of characters. It means the string should contain, at most, 2 '01' 0r '10' pairs. The first approach is that generate all binary strings, and if any binary string contains less than or equal to 2 distinct pairs of characters, include its count in the result. For the optimal solution, we can count a number of binary strings containing 0, 1, and 2 adjacent different pairs and sum them. Problem statement - We have given a positive ... Read More

Count Substrings with at least one occurrence of first K alphabet

Shubham Vora
Updated on 29-Aug-2023 18:07:29

65 Views

In this problem, we need to count substrings containing a minimum 1 occurrence of all K characters. Here, we will use two different approaches to solve the problem. The first approach takes all substrings of the given string, checks whether the substring contains all K characters, and counts such substrings containing all K characters. The second approach uses the sliding window technique to solve the problem. Problem statement - We have given a string alpha containing N characters. Also, we have given K, representing the string containing multiple occurrences of only the first K alphabetical characters. We ... Read More

Count of Strings of Array having given prefixes for Q query

Shubham Vora
Updated on 29-Aug-2023 17:59:57

161 Views

In this problem, we will count the number of strings containing query string as a prefix for each query string. We can traverse the list of query strings, and for each query, we can find a number of strings containing it as a prefix. Also, we can use the trie data structure to solve the problem. Problem statement – We have given an strs[] and queStr[] string array containing N and Q strings, respectively. We need to count the number of strings from the Strs[] array containing the queStr[i] string as a prefix for each string of ... Read More

Check if string S can be converted to T by incrementing characters

Shubham Vora
Updated on 29-Aug-2023 17:56:05

70 Views

In this problem, we will check whether it is possible to convert string S to T by incrementing the characters of S only once according to the given condition. Here, we can increment any characters by 'I' only once. So, If we need to increment any other character by 'I' times, the value of K should be greater than 26 + I. Problem statement – We have given a string S, T, and positive integer K. We need to convert the string S to T by following the rules below. We can take ... Read More

Advertisements