Shubham Vora

Shubham Vora

793 Articles Published

Articles by Shubham Vora

Page 20 of 80

Count of Prime Factors of N to be Added at each Step to Convert N to M

Shubham Vora
Shubham Vora
Updated on 02-Aug-2023 180 Views

In this problem, we will convert the number N to M by adding the one prime factor of N to itself and updating it in each operation. We will use the breadth−first search algorithm to solve the problem. We will find the prime factor of each updated N and insert it into the queue after adding it to the prime factor of N. Also, we will define functions to find the smallest prime factor of a particular number. Problem statement − We have given N and M integer values. We need to count the minimum number of operations required to ...

Read More

Construct Complete Binary Tree from its Linked List Representation

Shubham Vora
Shubham Vora
Updated on 02-Aug-2023 835 Views

In this problem, we will convert the linked list to the complete binary tree. We can assume the linked list as an array. The pth element of the linked list is the parent node of the binary tree's 2*p + 1 and 2*p + 2 elements. So, we can traverse through each element of the linked list and construct the binary tree. Problem statement − We have given a linked list containing N nodes. We need to construct the complete binary tree from the given linked list. Also, print the in−order traversal of the binary tree. Note − In the ...

Read More

Check if the given Permutation is a Valid BFS of a Given Tree

Shubham Vora
Shubham Vora
Updated on 02-Aug-2023 360 Views

In this problem, we will check whether we can get the permutation of 1 to N elements given array using the BFS (Breadth−first search) traversal with the given binary tree. Here, we will traverse the tree and find all possible permutations using the BFS traversal. After that, we can check whether any BFS traversal result matches the array permutation. Problem statement − We have given an array of size containing the first N positive integers in random order. Also, we have given a tree containing the first N numbers as a tree node. We need to check whether we ...

Read More

Check if the End of the Array can be Reached from a given Position

Shubham Vora
Shubham Vora
Updated on 02-Aug-2023 206 Views

In this problem, we will check whether we can reach the array’s end by moving back or ahead by nums[p] moves from the current position. The naïve approach to solve the problem is to check all possibilities to move into the array and see if we can reach the array’s end. Another approach is using the queue and BFS traversal in the array. In this tutorial, we will learn both approaches to check whether we can reach to the end of the array. Problem statement − We have given a nums[] array containing the positive integers. Also, we have given ...

Read More

Segregate 1s and 0s in separate halves of a Binary String

Shubham Vora
Shubham Vora
Updated on 28-Jul-2023 386 Views

In this tutorial, we need to separate all 1s and 0s of the given binary string in the two halves. Here, we need to take a substring from the given string and reverse it to separate 0s and 1s in different parts. Ultimately, we need to count the total number of reversals required for substring to separate 1s and 0s in two halves. Problem statement − We have given a binary string of even length. We need to take any substring from the given string multiple times and reverse it to separate it into two halves. We need to print ...

Read More

Modify string by replacing all occurrences of given characters by specified replacing characters

Shubham Vora
Shubham Vora
Updated on 28-Jul-2023 353 Views

In this problem, we need to replace the characters of the given string according to the characters given in the array of pairs of characters. We will discuss two different approaches to solving the problem. In the first approach, we iterate through the characters of the given string and pairs of characters to replace each character. In the second approach, we will use an array of length 26 to store the replaced character related to each character and change the character of the given string. Problem statement − We have given a string str containing N lowercase alphabetic characters. Also, ...

Read More

Minimum removals required such that a string can be rearranged to form a palindrome

Shubham Vora
Shubham Vora
Updated on 28-Jul-2023 1K+ Views

In this problem, we need to remove the minimum characters from the string and rearrange the remaining characters to make the string palindromic. To solve the problem, the first question we should ask ourselves is when we can make string palindromic. In below two cases, we can make string palindromic. If each character’s frequency is even in the given string. If only one character’s frequency is odd and all other characters' frequency is even. So, we need to remove minimum characters to make each character’s frequency even except for any single character. Problem statement − We have given ...

Read More

Minimize removal of substring of 0s to remove all occurrences of 0s from a circular Binary String

Shubham Vora
Shubham Vora
Updated on 28-Jul-2023 213 Views

In this problem, we require to remove all zeros from the given binary string. Also, we require to remove pair of consecutive zeros at once and count the total number of pairs of zeros removal. We can solve the problem by counting the number of pairs of consecutive zeros in the given string. In this tutorial, we will learn two different solutions to solve the problem. Problem statement − We have given circular binary string str of length N. We need to find the minimum number of consecutive zeros required to remove all zeros from the string. Sample Examples Input ...

Read More

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

Shubham Vora
Shubham Vora
Updated on 28-Jul-2023 279 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 from the string. Problem statement − We have given a binary string ‘str’ containing only 0 and 1. We require to find the minimum number of flips required so that the resultant string doesn’t contain any consecutive zeros. Sample Examples Input – 0101001 Output – 1 Explanation ...

Read More

Longest Non-Increasing Subsequence in a Binary String

Shubham Vora
Shubham Vora
Updated on 28-Jul-2023 417 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 start and end with either ‘0’ or ‘1’. To solve the problem, we will count prefix ‘1’s and suffix ‘0’ at each position of the string and find the maximum sum of prefix ‘1’s and suffix ‘0’s. Problem statement − We have given binary string str. We need to ...

Read More
Showing 191–200 of 793 articles
« Prev 1 18 19 20 21 22 80 Next »
Advertisements