Shubham Vora has Published 793 Articles

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

210 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

218 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

214 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

242 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

327 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

243 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

822 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

187 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

Rearrange and Update Array Elements as Specified by the given Queries

Shubham Vora

Shubham Vora

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

325 Views

In this problem, we will perform the given queries on the array elements. The queries contain the circular left rotation, right rotation, and updation of the array element. The logical part of solving the problem is array rotation. The naïve approach to rotating the array in the left direction is ... Read More

Print all Prime Levels of a Binary Tree

Shubham Vora

Shubham Vora

Updated on 22-Jul-2023 12:20:22

176 Views

In this problem, we will print all prime levels of the given binary tree. We will use the level order traversal technique to traverse each binary tree level and check whether all nodes contain the prime integer for the particular level. Problem statement − We have given a binary ... Read More

Advertisements