Prabhdeep Singh

Prabhdeep Singh

161 Articles Published

Articles by Prabhdeep Singh

Page 9 of 17

Maximum count of 0s between two 1s in the given range for Q queries

Prabhdeep Singh
Prabhdeep Singh
Updated on 17-May-2023 389 Views

A binary string is a string that only contains the zeroes and ones as the different characters in them. We are given a binary string and an array of a given length that will contain the pairs. Each pair defines the range, and in that range, we have to return the maximum number of zeros lying between two ones. We will implement two approaches one is the naive approach and another is the efficient approach. Let’s understand with the help of example Input String str = ‘1011010110’ Array Q[][] = {{0, 2}, {2, 5}, {0, 9}} Output: 1 1 3 ...

Read More

Minimum cost for constructing the subsequence of length K from given string S

Prabhdeep Singh
Prabhdeep Singh
Updated on 17-May-2023 307 Views

We will be given a string of length n, an integer k, and an integer array of length 26. The integer array defines the cost of each lowercase character and the string will contain only lowercase letters. We have to create a subsequence of length k from the given string at the minimum possible cost. We will use sorting to solve the problem and will implement a code with a full explanation. Sample Examples Input 1 Given string: acbcbac Given number: 4 Given array: {2, 3, 1, 2, 4, 5, 5, 6, 6, 2, 1, 0, 4, 3, 5, ...

Read More

Find an N-length Binary String having maximum sum of elements from given ranges

Prabhdeep Singh
Prabhdeep Singh
Updated on 17-May-2023 276 Views

We will be given an array that will contain the pairs which represent the range and their value will range from 0(inclusive) to N(exclusive). Here, N is the size of the binary string which we have to return as the answer. For all the given ranges we have to maximize the sum of the product of the frequencies of zero and one. We will implement two approaches one is the naive approach by finding all the strings and another is the efficient solution. Sample Examples Input 1 Given array: {{1, 3}, {2, 4}, {2, 5}} Length of string: 6 Output ...

Read More

Sort an array by swapping adjacent elements from indices that contains ‘1’ in a given string

Prabhdeep Singh
Prabhdeep Singh
Updated on 17-May-2023 561 Views

Sorting an array means ordering all the elements of the array in increasing order. Sorting an array by swapping adjacent elements means we can only swap elements that are adjacent to each other but we can swap adjacent elements any number of times. We will be given a binary string that will contain only two types of characters ‘0’ and ‘1’. If any character is ‘0’ in the given string then we cannot swap the element present at that index of the array with adjacent elements. Sample Examples Input 1 Given array: {1, 4, 3, 2, 5, 7, 6} Given ...

Read More

Minimum number of flipping adjacent bits required to make given Binary Strings equal

Prabhdeep Singh
Prabhdeep Singh
Updated on 17-May-2023 541 Views

A binary string is a string that contains only two different types of characters 0 and 1. We will be given two binary strings of the same length and our task is to make both of them equal by toggling two adjacent characters of the first string. Also, we have to do this in a minimum number of operations as possible. If it is not possible to convert the first string to the second string then return -1. Sample Example Input 1 string1: 101001 string 2: 100110 Output: 2 Explanation − We can toggle the second index character and the ...

Read More

Max count of N using digits of M such that 2 and 5, and, 6 and 9 can be treated as same respectively

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

Max count is a count which is the maximum possible. Here we have given an integer N and a string of integer M. Our task is to return the maximum count of making the number N using the digits of the string of integer M. Also given that, we can be treated 2 and 5, and, 6 and 9 can be same respectively. Sample Examples Input 1 N = 29 M = "2569783" Output 1: 2 Explanation − As 5 is the same as 2 and 6 is the same as 9 so we have a total of two ...

Read More

Find the smallest number formed by inserting a given digit

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

Inserting a number in the given number means adding a new given digit in the given number either at the front, end, or in between the numbers. We have given a number and a digit and have to add the digit in the number in a way such that the resultant new number will be minimum as possible. We will convert the number into a string to make the work of insertion easy. Also, the given number can be negative also so we have to consider this case. Sample Examples Input1 Given number: 124 Given digit: 3 Output: 1234 ...

Read More

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

Prabhdeep Singh
Prabhdeep Singh
Updated on 16-May-2023 208 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 378 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 289 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
Showing 81–90 of 161 articles
« Prev 1 7 8 9 10 11 17 Next »
Advertisements