Found 7197 Articles for C++

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

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

184 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

Validating UPI IDs using Regular Expressions

Shubham Vora
Updated on 27-Oct-2023 16:13:48

2K+ Views

In this problem, we will validate the UPI id using the regular expression. The UPI is the unified payment interface that is given to each customer, and other people can use it to transfer money to you. The UPI id contains alphanumeric characters. The UPI id should always contain a ‘@’ character. The UPI id should not have white spaces. The UPI id may have a dot(.) or hyphen(-). Problem statement − We have given an upi id in the string format. We need to validate the UPI id using the regular expression. Sample Examples Input: upi ... Read More

Minimum deletion such that XOR of adjacent digits is atmost 1

Shubham Vora
Updated on 27-Oct-2023 14:56:08

135 Views

In this problem, we will learn to find the count of minimum deletion required so that when we take the XOR of any two adjacent elements, we should either get 0 or 1. We will use the properties of the XOR operations to solve the problem. For example, when we take XOR of the same numbers, we always get 0; when we take XOR of the consecutive even and odd number, we get 1. Problem Statement We have given a num_str string containing the numeric digits. We need to count the minimum deletions required so that the XOR ... Read More

Maximum moves to reach destination character in a cyclic String

Shubham Vora
Updated on 23-Oct-2023 15:59:58

132 Views

In this problem, we will find the maximum distance from the initial to the final character in the cyclic string. The basic approach to solve the problem is to find the next closest final character for every initial character and update the maximum distance if required. Another approach traverses the string in reverse order and keeps track the index of the last final character. When we get an initial character, we measure the distance and update the maximum distance if required. Problem statement − We have given an str string containing the 3 characters, and the length equals N. Also, ... Read More

Maximize value of Binary String in K steps by performing XOR of Substrings

Shubham Vora
Updated on 23-Oct-2023 15:11:47

420 Views

In this problem, we will maximize the value of the binary string by performing K XOR operations of substrings of the given binary string. To maximize any binary string, we should maximize the substring starting from the leftmost zero. For example, to maximize the ‘11001’ string, we need to choose another substring in such a way that we can maximize the ‘001’ substring. Problem Statement We have given a binary string named bin_str containing N characters. We have to maximize the value of the binary string in K operations by taking the XOR operation of any two substrings. It ... Read More

Maximize “10” Subsequences by replacing at most one 0 with 1

Shubham Vora
Updated on 23-Oct-2023 14:57:07

177 Views

In this problem, we need to maximize the ‘10’ subsequences in the given binary string by replacing the 0 or 1 ‘0’ character with ‘1’. We can replace each ‘0’ with ‘1’ one after another and find a maximum number of ‘10’ subsequences in the updated string. Problem statement − We have given a binary string named str1 containing only 0 and 1 characters. We can replace at most one ‘0’ with ‘1’ and need to find the maximum number of ‘10’ subsequences in the given string. Sample Examples Input  str1 = "10110" Output  4 Explanation The ‘10110’ ... Read More

Longest Substring of A that can be changed to Substring of B in at most T cost

Shubham Vora
Updated on 23-Oct-2023 14:34:21

242 Views

In this problem, we will find the longest substring of A to convert it to a substring of B starting from the same index in less than T cost. We will use the binary search algorithm to find the maximum length of the substring which follows the given condition. However, the naïve approach to solving the problem is to find all substrings following the conditions in the problem statement and take the substring with maximum length. Problem statement − We have given a string A and B of length N. Also, we have given a total cost, ‘T’. The ... Read More

How to validate ISIN using Regular Expressions?

Shubham Vora
Updated on 31-Aug-2023 10:05:54

1K+ Views

In this problem, we will use the regular expression to validate the ISIN number in C++. The ISIN stands for the International Securities Identification Number. It is a unique code to identify stocks, financial bonds, etc. The length of the ISIN number can be 12 or 14, which provides international recognization of the particular stuff. Let’s understand the format of the ISIN number. Country code − It starts with two characters of the country code. Identifier − It contains 9 alphanumeric characters after the country code. Checksum − It contains the single digit which is used to detect errors ... Read More

Find two unique Palindrome Strings using given String characters

Shubham Vora
Updated on 20-Oct-2023 15:00:47

162 Views

In this problem, we will construct two palindromic strings using the given string’s characters. We can use the character’s frequency to solve the problem. We can construct two new palindromic strings only if both characters’ frequencies are even or if any characters have an even frequency and others have an odd frequency. Problem statement − We have given a string alpha containing two different characters and a size equal to N. We need to construct two palindromic strings using the characters of the alpha, which are not the same as the given string alpha. Sample Examples After incrementing each character ... Read More

Find the final String by incrementing prefixes of given length

Shubham Vora
Updated on 31-Aug-2023 09:20:34

154 Views

In this problem, we need to increase each character of multiple prefixes of size given in the array. The naïve approach to solving the problem is to take each prefix of the size given in the array and increment each character of the prefix by 1. The best approach is to create the prefix array using the given array and update each string character in the single iteration. Problem statement − We have given a string alpha of length N. Also, we have given a prefixes array containing the positive integer. The prefixes[i] represent that take prefix of length prefixes[i] ... Read More

Advertisements