Found 1860 Articles for Data Structure

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

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

157 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

182 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

229 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

147 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

303 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

185 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

139 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

136 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

425 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

Advertisements