Shubham Vora

Shubham Vora

793 Articles Published

Articles by Shubham Vora

Page 18 of 80

Number of substrings having an equal number of lowercase and uppercase letters

Shubham Vora
Shubham Vora
Updated on 10-Aug-2023 361 Views

In this problem, we need to count the total number of strings of the given string containing an equal number of lowercase and uppercase characters. The naïve approach to solving the problem is to find all substrings and count the total number of substrings with an equal number of lowercase and uppercase characters. The efficient approach is using the subarray sum problem. We can consider lowercase characters as -1 and uppercase characters as +1, and we will learn both approaches to solve the problem. Problem statement- We have given string str containing the lowercase and uppercase alphabetical characters. We need ...

Read More

Modify a string by circularly shifting each character to the right by respective frequencies

Shubham Vora
Shubham Vora
Updated on 10-Aug-2023 276 Views

In this problem, we need to right-shift each character of a given string by its frequency. To solve the problem, we can count the frequency of each character and store it in a data structure like an array or map. After that, we can use the ASCII values of the characters to right-shift each character by their frequency. Problem statement- We have given string str containing lowercase characters and a length equal to N. We need to right-shift each character of the string by the frequency of that particular character in the given string. Sample examples Input – str = ‘tutorialspoint’ ...

Read More

Minimum subsequences of a string A required to be appended to obtain the string B

Shubham Vora
Shubham Vora
Updated on 10-Aug-2023 374 Views

In this problem, we need to construct the str2 by using the subsequences of the str1. To solve the problem, we can find subsequences of the str1 so that it can cover the substring with a maximum length of str2. Here, we will learn two different approaches to solving the problem. Problem statement – We have given two strings, str1, and str2, of different lengths. We need to construct the str2 from the str1 by following the condition below. Pick any subsequence from the str1, and append it to the new string, which is empty initially. We need to return ...

Read More

Count permutations possible by replacing ‘?’ characters in a Binary String

Shubham Vora
Shubham Vora
Updated on 10-Aug-2023 238 Views

In this problem, we have given a string containing 0, 1, and ? characters. We need to find permutations of the string by replacing ‘?’ with 0 and 1. The logic to solve the problem is that we can replace every ‘?’ with either 0 or 1. So, by replacing one ‘?’, we can generate two different permutations, and by replacing N ‘?’ with 2 possibilities, we can generate 2^N permutations. In this tutorial, we will learn two different approaches to solving the given problem. Problem statement – We have given string str containing ‘0’, ‘1’ and ‘?’ characters. We ...

Read More

Count new pairs of strings that can be obtained by swapping first characters of pairs of strings from given array

Shubham Vora
Shubham Vora
Updated on 10-Aug-2023 234 Views

In this problem, we need to select the pair of strings and swap their first character. After that, we need to count the total number of new pairs. We can solve the problem by swapping the first character of each pair and checking whether it exists in the array. The efficient approach to solve the problem can be using the hashmap data structure. Problem statement – We have given an array containing N strings. We can take any of two strings from all array elements and swap the first characters of both strings. We need to count the total ...

Read More

Check if the number formed by concatenating all array elements is a Harshad number or not

Shubham Vora
Shubham Vora
Updated on 10-Aug-2023 230 Views

In this problem, we have given the array of integers. We need to combine all elements in a single integer and check if it is a Harshad number. Before we move with the solution, let’s understand Harshad number. All numbers are Harshad numbers which are divisible by the sum of their digits. For example, 12 is Harshad number, as 12 is divisible by 3 = 1 + 2. To solve the problem, we can combine all array elements, and after that, we can check whether the resultant number is the Harshad number. Problem statement – We have given an array ...

Read More

Check if all characters of a string can be made equal by increments or decrements

Shubham Vora
Shubham Vora
Updated on 10-Aug-2023 273 Views

In this problem, we need to check if we can make all characters of strings equal by increment and decrement operations. We can get the weight of each character based on their ASCII values and check whether the total weight can be used to make all characters equal. Problem statement – We have given string str of length N containing lowercase alphabetical characters. We need to check whether we can make all characters of the string equal by choosing any of two characters, increasing one, and decreasing another by 1. If possible, print ‘yes’, else ‘no’. Sample examples Input– ...

Read More

Size of all Connected Non-Empty Cells of a Matrix

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

In this problem, we will find the size of sets of all non−empty connected cells. We will learn two different approaches for finding the size of all non−empty connected cells of a matrix. In the first approach, we will use the breadth−first search algorithm, and in the second approach, we will use the depth−first search algorithm to traverse the matrix and find the size of all non-empty connected cells. Problem statement − We have given matrix[][] 2D array containing only 0 and 1. Here, 0 represents the empty cell, and 1 represents the non−empty cells. We need to find the ...

Read More

Restore a Shuffled Queue as Per given Conditions

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

In this problem, we have given the persona names and the number of taller people standing in front of that people. We can sort the position of the people according to the number of taller people standing in front of any person. After that, we update the position of each person according to the nums[] array value to get the original queue. Problem statement − We have given an array persons[] and nums[]. The persons[] array contains the person's name, and the nums[] array contains the number of taller people standing in front of each person. This queue is shuffled, ...

Read More

Minimum Nodes to be Colored in a Graph such that every Node has a Colored Neighbour

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

In this problem, we will color the minimum nodes of the graph such that each node of the graph has a colored node at the maximum distance 1. The simple logic to minimize the count of the colored node is that either color the nodes which are at an odd distance or color the nodes at an even distance. So, we can color the alternative node, and for each node, we can have a colored node at most distance 1. Problem statement − We have given a graph containing N nodes and E edges. It is given that we can ...

Read More
Showing 171–180 of 793 articles
« Prev 1 16 17 18 19 20 80 Next »
Advertisements