Data Structure Articles

Page 77 of 164

Maximize the missing values in a given time in HH:MM format

Prabhdeep Singh
Prabhdeep Singh
Updated on 16-May-2023 232 Views

A string will be given to us of length five which represents the time in the HH:MM format. There may be some ‘?’ present in the string and we have to replace them with any number such that the result is the valid time which could be the maximum possible. Also, the given string numbers will be valid, and ‘:’ will be present at the exact position of the string. We will use the two approaches first the brute force, and another the efficient approach. Sample Examples Input 1 Given string: 12:5? Output: 12:59 Explanation We have only one ...

Read More

Generate all possible strings formed by replacing letters with given respective symbols

Prabhdeep Singh
Prabhdeep Singh
Updated on 16-May-2023 404 Views

Generating all possible strings is to replace a character of a string with a respective symbol and produce all possible strings. We will be given a string ‘s’ of size ‘N’ and an unordered map ‘mp’ of a pair of characters of size ‘M’. Here we can replace the mp[i][0] with mp[i][1] in the string ‘s’ and by doing this our task is to generate all possible strings. Sample Examples Input: s = “xyZ”, mp = {‘x’ : ‘$’, ‘y’ : ‘#’, ‘Z’ : ‘^’} Output: xyZ xy^ x#Z z#^ $yZ $y^ $#Z $#^ Explanation − In the ...

Read More

Find Binary string by converting all 01 or 10 to 11 after M iterations

Prabhdeep Singh
Prabhdeep Singh
Updated on 16-May-2023 319 Views

A binary string is a string that consists of only two different types of characters and that is ‘0’ and ‘1’. We will be given a binary string and the number m. We have to apply the operation to convert all the consecutive occurrences of the 0 and 1 that are ‘01’ and ‘10’ to ‘11’. One more condition is there that there must be only one neighbor of ‘0’ can be ‘1’. We can traverse over the string only m times where m will be given. Let’s understand with the following example Input 1: Given binary string: ‘01000101’ Given ...

Read More

Next greater number on the basis of the precedence of digits

Prabhdeep Singh
Prabhdeep Singh
Updated on 16-May-2023 220 Views

In the normal number system, 0 is the smallest digit while 9 is the largest digit. In this problem, we will be given a list of the length 10, and starting from index 0 to index 9 it represents a digit, which indicates the priority of that digit and the list will be in increasing order means the digit present at the last index is the with highest priority. We will be given a number also and we have to find the next number which is the just greater than the current number. Input 1: Given number = “123” ...

Read More

Check if the given String can be split only into subsequences ABC

Prabhdeep Singh
Prabhdeep Singh
Updated on 16-May-2023 342 Views

A subsequence of a string means part of a string in which characters can be taken from anywhere of the string (zero or more elements) without changing the order of the characters and forming a new string. In this problem, we have given a string of length N where every character of the string belongs to either ‘A’, ‘B’, or ‘C’ character. Our task is to find that the string can be split only into subsequences “ABC” or Not. If the string is split only into subsequences “ABC” then return “yes” otherwise return “no”. Input 1: str = “AABCBC” ...

Read More

Check if the Decimal representation of the given Binary String is divisible by K or not

Prabhdeep Singh
Prabhdeep Singh
Updated on 16-May-2023 689 Views

A binary string is a string that consists of only two different types of characters and that is ‘0’ and ‘1’, hare base is 2. And a decimal representation means each digit is lie between ‘0’ to ‘9’, here the base is 10. Here we have given a string of binary numbers and an integer k. we have to check if the decimal representation of the given binary string is divisible by k or not. If it is divisible then we have to return ‘yes’ otherwise return ‘no’. In the conversion of binary to decimal, we convert a base 2 ...

Read More

Maximize the sum of selected numbers from an array to make it empty

Prabhdeep Singh
Prabhdeep Singh
Updated on 16-May-2023 268 Views

We will be given an array and have to choose an element from it and add that element to the sum. After adding that element to the sum, we have to remove three elements from the array if they exist current number, current number -1, and current number + 1. By this method we will make the array empty and will get a sum. At the end, we have to make the sum maximum. Input: [ 1, 2, 3] Output: 4 Explanation At first, we can have three moves, delete 1, 2, or 3. Let ...

Read More

Count of element in an array whose set bits are in a multiple of K

Tapas Kumar Ghosh
Tapas Kumar Ghosh
Updated on 10-May-2023 453 Views

The set bit is a binary representation form of 0 and 1. This digit 1 is called a set bit in reference to the computer. Let’s take an example to understand the setbit calculation − Let’s take an example to understand the setbit calculation − The set bit calculation of integer 96 is Let’s say we want to set the bit to sum of 96. So as shown in the above representation, we will set bit 1 to those array elements whose total will be 96. This way we will form 2 sets of bit. Therefore, if we take ...

Read More

Minimum Bottleneck Spanning tree(MBST)

Tapas Kumar Ghosh
Tapas Kumar Ghosh
Updated on 10-May-2023 885 Views

The Minimum Bottleneck Spanning tree is an undirected graph whose highest weight is considered as minimum as possible. Let’s take an example to understand the Minimum Bottleneck Spanning tree. In Figure I, we observe that there are three possible ways of spanning trees that have the common edge 2 and it means there is no other tree having a bottleneck value less than 2. Therefore, all these trees verify as Minimum Bottleneck Spanning trees. How we can say that the MST is MBST? There are the following points to understand the MST to be MBST − MBST ...

Read More

Array Range Queries to find the Maximum Armstrong number with updates

Tapas Kumar Ghosh
Tapas Kumar Ghosh
Updated on 10-May-2023 512 Views

The Array range queries are a new interest of data structure. In this query, we have set the random element to the array and given the general query problem to solve the data structure problem efficiently. Armstrong number is the total of its digits' cubes. For example- 0, 1, 153, 370, 371, and 407 are Armstrong numbers. Let’s take an example to understand the Armstrong number Example 1 − The given number is 371 and check whether the number is Armstrong or not. 3*3*3 + 7*7*7 + 1*1*1 = 371 Hence, this is Armstrong number. Example 2 − The given ...

Read More
Showing 761–770 of 1,635 articles
« Prev 1 75 76 77 78 79 164 Next »
Advertisements