Shubham Vora

Shubham Vora

793 Articles Published

Articles by Shubham Vora

Page 8 of 80

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

Shubham Vora
Shubham Vora
Updated on 29-Aug-2023 216 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
Shubham Vora
Updated on 29-Aug-2023 251 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
Shubham Vora
Updated on 29-Aug-2023 289 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
Shubham Vora
Updated on 29-Aug-2023 209 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
Shubham Vora
Updated on 29-Aug-2023 503 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
Shubham Vora
Updated on 29-Aug-2023 229 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

Reconstruct original string from resultant string based on given encoding technique

Shubham Vora
Shubham Vora
Updated on 25-Aug-2023 188 Views

In this problem, we need to construct the original string from the given string. The given string is formed from the original string using the given rules. Here, we can use the given encryption rule and encrypted string to find the decrypted string by applying the encryption rule in reverse order. Problem statement – We have given a binary string bin_str of length N and positive integer k. The binary string is constructed from the ‘enc’ string by following the below operations and using the x value. If enci-k is equal to 1, bin_stri is equal to 1. If ...

Read More

Python3 Program for Longest subsequence of a number having same left and right rotation

Shubham Vora
Shubham Vora
Updated on 25-Aug-2023 176 Views

In this problem, we will find the length of the longest subsequence of the given string such that it has the same left and right rotation. We can solve the problem by finding all subsequences of the given string and checking whether particular subsequences have the same left and right rotation. The other approach uses the observation that string can have only the same left and right rotation if it contains a single character or alternate character and the left is even. Problem statement – We have given an alpha string containing only numeric digits. We need to find ...

Read More

Minimum Characters to be Replaced in given String to make all Characters Same

Shubham Vora
Shubham Vora
Updated on 25-Aug-2023 429 Views

In this problem, we will find a minimum number of string characters needed to be replaced to make all characters. In the first approach, we will find the minimum count of the replaceable characters by counting the frequency of each character in the given string. In another approach, we will determine the cost to convert all string characters to a particular character and take the minimum value from that. Problem statement – We have given a string alpha containing N alphabetical characters. We need to find the minimum number of characters to replace to make all string characters equal. Sample ...

Read More

Minimize Partitions in given String to get Another String

Shubham Vora
Shubham Vora
Updated on 25-Aug-2023 181 Views

In this problem, we need to construct one string by slicing the other string. We can use the longest common substring to solve the problem. We can find the longest common substring between both strings, slice str1 into 1 or 2 parts, and remove the substring from str2. Again, we find the longest common substring in updated strings and follow it until str2 becomes empty. In this way, we can solve the problem. Problem statement – We have given str1 and str2 strings of different lengths. We need to construct the string str2 by slicing and concatenating the parts of ...

Read More
Showing 71–80 of 793 articles
« Prev 1 6 7 8 9 10 80 Next »
Advertisements