Found 7346 Articles for C++

Check if uppercase characters in a string are used correctly or not

Shubham Vora
Updated on 18-Jul-2023 16:08:57

124 Views

Problem Statement We have given a string ‘str’, containing the alphabetical characters in uppercase or lowercase. We require to check if uppercase characters are used correctly in the string. Followings are the correct way to use uppercase characters in the string. If only the first character is in uppercase, the other characters are in lowercase. If all characters of a string are in lowercase. If all characters of the string are in uppercase. Sample examples Input "Hello" Output "valid" Explanation In "Hello", only the first character is in uppercase, and others are in lowercase, so it ... Read More

Sort an Array of Strings in Lexicographical Order

Shubham Vora
Updated on 17-Jul-2023 16:36:54

623 Views

In this problem, we will sort the array of strings in the lexicographical order. There are various sorting algorithms to sort the array of strings. In this tutorial, we will use the built−in sort() method to sort the strings. Also, we will use the merge sort algorithm, one of the efficient approaches to sort the array of strings. Problem statement − We have given an str[] array containing N strings. We need to sort all strings in the lexicographical order. Sample examples Input str[] = {"tutorials", "point", "save", "java", "c++"} Output c++, java, point, save, tutorials ... Read More

Reverse given Range of String for M queries

Shubham Vora
Updated on 17-Jul-2023 16:34:47

200 Views

In this problem, we will perform M reverse queries on the given string according to the array values. The naïve approach to solving the problem is to reverse each string segment according to the given array value. The optimized approach uses the logic that when we reverse the same substring two times, we get the original string. Problem statement − We have given an alpha string containing the alphabetical characters. Also, we have given an arr[] array of size M containing the positive integers. We need to perform the M operations on the given string and return the final ... Read More

Parity of Count of Letters whose Position and Frequency have Same Parity

Shubham Vora
Updated on 17-Jul-2023 16:32:47

89 Views

In this problem, we will count the number of characters whose frequency and position have the same parity and print the count of the number as odd or even. To solve the problem, we can find the frequency of each character in the string, and count total characters whose freqeuncy and position have the same parity. After that, we can print the odd or even answer based on the counts. Problem statement − We have given a string alpha containing only lowercase english alphabetical characters. We need to check whether the number of characters having equal parity of their alphabetical ... Read More

Minimize Removal from Front or End to Make the Binary String at Equilibrium

Shubham Vora
Updated on 17-Jul-2023 16:26:57

46 Views

In this problem, we will print the minimum number of characters that we need to remove from the start and end to make the count of ‘1’ and ‘0’ the same in the given string. If we find the largest substring with an equal number of ‘1’ and ‘0’, we can get the answer by subtracting the substring length from the given string’s length. We will use the prefix sum technique to find the largest substring having an equal number of ‘1’ and ‘0’. Problem statement − We have given the ‘bin_str’ binary string containing the N characters. We ... Read More

Minimize Max Frequency Difference of 0 & 1 by Dividing Binary String into K Disjoint Subsequence

Shubham Vora
Updated on 17-Jul-2023 16:25:19

53 Views

In this problem, we will divide the given binary string into the K subsequences such that we can minimize the maximum absolute difference of count of ‘1’ and ‘0’ in the given string. The logic to solve the problem is to create a maximum pair of 0 and 1 in subsequences. So, we can get the minimum difference between each subsequence. Problem statement − We have given a bin_str binary string of length N. We have also given the positive integer K. We need to divide the given string into the K disjoint subsequences to minimize the maximum absolute ... Read More

Maximum Product of First and Last Character of String after Rotation

Shubham Vora
Updated on 17-Jul-2023 16:22:35

43 Views

In this problem, we will find the maximum possible product of the first and last digits of the string by rotating the string multiple times. The naïve approach is that find all rotations of the string, take the product of the first and last character, and choose the maximum product as an answer. Another approach is to find the product of every adjacent pair of characters and choose the maximum product. Problem statement − We have given a string num containing the numeric digits. We need to find the maximum product of the first and last character of the given ... Read More

Make Binary Strings Equal by Replacing 2nd Bit Repeatedly

Shubham Vora
Updated on 17-Jul-2023 16:19:04

66 Views

In this problem, we need to convert the bin1 string to the bin2 string by replacing the second character of the bin1 string with the minimum or maximum of the first and second characters and removing the first character. As we need to remove the initial character, we need to ensure that the last len2 − 1 character are the same in both strings. Also, we need to ensure that we can get the first character of the second string by performing the given operation with the starting characters of the bin1 string. Problem statement − We have given bin1 ... Read More

Longest Substring of given Characters by Replacing at Most K Characters for Q Queries

Shubham Vora
Updated on 17-Jul-2023 16:14:29

109 Views

In this problem, we have given M queries, and after performing each query on the given string, we need to print the maximum length of the string having only the ‘ch’ character. We will use the tabulation method of dynamic programming to find the maximum possible length of the substring after replacing the at most K characters with the given character. Problem statement − We have given a string alpha of length N and que[] array containing M queries of type {K, ch}, where K is a positive integer, and ch is a character. It is given that for each ... Read More

Longest Subsequence with Same Char as Substrings and Difference of Frequency at Most K

Shubham Vora
Updated on 17-Jul-2023 16:12:19

126 Views

In this problem, we will find the maximum length of the subsequence such that it should contain the contiguous characters, and the frequency difference of all characters won’t differ more than K. We need to find all possible subsequences of the given string and check whether it contains every character continuously and maximum frequency difference to get the output. Problem statement− We have given a string alpha containing the lowercase alphabetical characters. Also, we have given the positive integer K. We need to find the maximum length of the subsequence of the given string such that it follows the below ... Read More

Advertisements