Shubham Vora

Shubham Vora

793 Articles Published

Articles by Shubham Vora

Page 4 of 80

Maximum moves to reach destination character in a cyclic String

Shubham Vora
Shubham Vora
Updated on 23-Oct-2023 183 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
Shubham Vora
Updated on 23-Oct-2023 512 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 sum by picking Array element to left of each ‘1’ of a Binary String

Shubham Vora
Shubham Vora
Updated on 23-Oct-2023 146 Views

In this problem, we will find the maximum sum of array elements by picking up unselected elements at the left from the current 1's index. We can use the vector list and sort() method to solve the problem or priority queue. The priority queue inserts the element in the sorted order. Problem Statement We have given a binary string alpha and arr[] of the same length. We need to pick all '1' of alpha one by one and take the maximum element which is not picked from the subarray of arr[] formed using 0 to p elements. Here, ...

Read More

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

Shubham Vora
Shubham Vora
Updated on 23-Oct-2023 232 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

Make all Strings palindrome by swapping characters from adjacent Strings

Shubham Vora
Shubham Vora
Updated on 23-Oct-2023 836 Views

In this problem, we will make all strings of the given array palindromic by swapping the characters of the adjacent string. To solve the problem, we will try to make the character the same at p and str_len - p - 1 index in all strings, and it is only possible if overall characters at pth index and (str_len - p - 1) index is same. Problem statement - We have given an arr containing multiple strings of the same length equal to N. We need to count the minimum number of operations required to make all strings of ...

Read More

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

Shubham Vora
Shubham Vora
Updated on 23-Oct-2023 285 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

Find two unique Palindrome Strings using given String characters

Shubham Vora
Shubham Vora
Updated on 20-Oct-2023 214 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 Strings formed by replacing prefixes of given String with given characters

Shubham Vora
Shubham Vora
Updated on 20-Oct-2023 211 Views

In this problem, we will form a triangle from the given string. The triangle will contain the rows equal to the string length - 1, and in each row, we replace the starting characters equal to the row number with '.' Character. We can use the loop to form each row of the string or string constructor and substr() method. Problem statement - We have given a string alpha. We need to print the string in the triangle pattern. We need to start the triangle with the alpha string and replace the first character of the previous string ...

Read More

Count ways to select three indices from Binary String with different adjacent digits

Shubham Vora
Shubham Vora
Updated on 16-Oct-2023 298 Views

In this problem, we will find the number of pairs of 3 indices so that any adjacent indices don’t have the same value in the pair. We can get the output by checking each pair of 3 indexes, but it can be more time-consuming. Another approach to solving the problem is to take the current index and also take the index from left and right, which doesn’t contain a similar value to the current index's value. This way, we can count the total number of pairs each index can form and sum them to get the output. Problem statement − ...

Read More

Count even indices of String whose prefix has prime number of distinct Characters

Shubham Vora
Shubham Vora
Updated on 16-Oct-2023 227 Views

In this problem, we will find total invalid characters in the given string. If total distinct characters till the particular even index is prime, we can say the character is invalid. We can use the map data structure to count the total number of distinct characters while traversing the string. Also, we can use the string of characters to keep track of the distinct digits. Also, for every character, we can check whether its index is even and whether distinct characters are prime. Problem statement – We have given a string alpha containing the N characters. We need to find ...

Read More
Showing 31–40 of 793 articles
« Prev 1 2 3 4 5 6 80 Next »
Advertisements