Shubham Vora has Published 957 Articles

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

191 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

258 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

169 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

700 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

141 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

265 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

140 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

Print all Palindromic Levels of a Binary Tree

Shubham Vora

Shubham Vora

Updated on 22-Jul-2023 12:17:34

191 Views

In this problem, we will print each palindromic level of the given binary tree. We can use the breadth−first search algorithm to traverse each level of the given binary tree and check whether a particular level of the binary tree is palindromic. If yes, we print the level in the ... Read More

Print all Nodes Except Rightmost Node of Every Level of the Binary Tree

Shubham Vora

Shubham Vora

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

146 Views

In this problem, we will print all the nodes of the binary tree except the rightmost node of each level. We will use the level order traversal to traverse the binary tree, and we won’t print the last node of each level, which is the rightmost node. Problem statement − ... Read More

Minimize the Maximum difference between Adjacent Elements in an Array

Shubham Vora

Shubham Vora

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

712 Views

In this problem, we will minimize the maximum difference between adjacent elements by removing any M elements from the array. The naïve approach to solving the problem is to pick total N − M array elements and check which set contains the minimum or maximum adjacent difference. The optimized approach ... Read More

Advertisements