Shubham Vora has Published 962 Articles

Minimize flips required such that string does not any pair of consecutive 0s

Shubham Vora

Shubham Vora

Updated on 28-Jul-2023 12:58:09

80 Views

Here, we require to manipulate the binary string so that it doesn’t contain any consecutive zeros. If we find consecutive zeros, we need to change any zero to 1. So, we require to count the total number of 0 to 1 conversion we should make to remove all consecutive zeros ... Read More

Longest Non-Increasing Subsequence in a Binary String

Shubham Vora

Shubham Vora

Updated on 28-Jul-2023 12:55:09

165 Views

In this problem, we require to find the longest non-increasing subsequence of the given string. The meaning of non-increasing is either character should be the same or in decreasing order. As binary string contains only ‘0’ and ‘1’, the resultant string should start with ‘1’ and end with ‘0’, or ... Read More

Length of longest subset consisting of A 0s and B 1s from an array of strings

Shubham Vora

Shubham Vora

Updated on 28-Jul-2023 12:52:55

70 Views

In this problem, we need to find the longest subset containing at most A 0s and B1s. All we need to do is find all possible subsets using the array elements and find the longest subset containing maximum A 0s and B1. In this tutorial, first, we will learn the ... Read More

Construct a K-length binary string from an array based on given conditions

Shubham Vora

Shubham Vora

Updated on 28-Jul-2023 12:50:54

88 Views

In this tutorial, we require to construct a binary string of length K such that it should contain ‘1’ at the ith index if a subset-sum equal to I is possible using array elements. We will learn two approaches to solving the problem. In the first approach, we will use ... Read More

Check if a string can be split into 3 substrings such that one of them is a substring of the other two

Shubham Vora

Shubham Vora

Updated on 28-Jul-2023 12:48:15

77 Views

In this problem, we need to split the given string in such a way that the third substring can be a substring of the first two substrings. Let’s think about the solution. The third string can be a substring of the first two string only if the first two string ... Read More

Check if a Binary String can be sorted in decreasing order by removing non-adjacent characters

Shubham Vora

Shubham Vora

Updated on 28-Jul-2023 12:46:14

76 Views

In this problem, we need to sort the given binary string in decreasing order by removing only non-adjacent elements. To solve the problem, we require to remove all zeros which are placed before ones in the binary string. If we find two consecutive ones after two consecutive zeros at any ... Read More

Minimum prefixes required to be flipped to convert a Binary String to another

Shubham Vora

Shubham Vora

Updated on 28-Jul-2023 12:44:23

134 Views

In this problem, we need to convert the first binary string to the second binary string by flipping the prefix of the first string. To get the minimum prefix flip, we require to iterate through the end of the string, and if we find mismatched characters in both strings, we ... Read More

Find the Number of 'X' Total Shapes

Shubham Vora

Shubham Vora

Updated on 22-Jul-2023 14:50:19

99 Views

In this problem, we need to find the total number of ‘X’ shapes in the given matrix. We can construct the single ‘X’ shape using 1 or more adjacent ‘X’ elements. We can use the DFS (depth−first search) technique to solve the problem. For each ‘X’ element, we can find ... Read More

Sum of Minimum and Maximum Elements of all Subarrays of Size K.

Shubham Vora

Shubham Vora

Updated on 22-Jul-2023 12:47:06

366 Views

In this problem, we need to take the maximum and minimum elements of all sub−array of length K and add them to get the answer. The first solution approach is that traverse through all sub−arrays of size K, find the minimum and maximum element of each sub−array, and add ... Read More

Reduce the Array to Atmost one Element by the Given Operations

Shubham Vora

Shubham Vora

Updated on 22-Jul-2023 12:42:30

67 Views

In this problem, we will reduce the array size to 1 or 0 by performing the given operations in each turn. We can sort the array in each turn to get the maximum elements in each iteration. Also, we can use the head data structure to improve the performance of ... Read More

Advertisements