Found 27104 Articles for Server Side Programming

Maximize given function by selecting equal length substrings from given Binary Strings

Prabhdeep Singh
Updated on 26-Jul-2023 10:50:29

117 Views

Two binary strings str1 and str2 of the same length are given and we have to maximize a given function value by choosing the substrings from the given strings of equal length. The given function is such that − fun(str1, str2) = (len(substring))/(2^xor(sub1, sub2)). Here, len(substring) is the length of the first substring while xor(sub1, sub2) is the xor of the given substrings as they are binary strings so it is possible. Sample Examples Input1: string str1 = 10110 & string str2 = 11101 Output: 3 Explanation We can choose a lot of different sets of strings ... Read More

Minimum number of adjacent swaps to reverse a String

Prabhdeep Singh
Updated on 26-Jul-2023 10:42:32

333 Views

A string str is given and we can swap only adjacent characters to make the string reverse. We have to find the number of minimum moves required to make the string reverse just by swapping the adjacent characters. We will implement two approaches to find the required solution with the explanation and the implementation of the code. Sample Examples Input1: string str1 = “shkej” Output: 10 Explanation First, we will take the last character to the first position which will take 4 swappings, and then the string will be “jshke”. Then we will move ‘e’ to the second ... Read More

Minimum count of prefixes and suffixes of a string required to form a given string

Prabhdeep Singh
Updated on 26-Jul-2023 10:40:31

245 Views

Prefixes are the substring from the given string that starts from the zeroth index and can go up to length 1 to the size of the string. Similarly, the suffix is the substring of any length 1 to the size of the string and ends at the last index. We will be given two strings and have to create the first string by using any number of prefixes and suffixes of the second string in any way. If it is not possible to create the given string from the given methods then we will return -1. Sample Examples Input 1: ... Read More

Encrypt the string

Prabhdeep Singh
Updated on 26-Jul-2023 10:29:46

1K+ Views

Encryption is the technique to change the data by using some techniques or certain steps so it changes to another information or the previous information cannot be gathered from it directly. For encryption, we have to follow certain steps that are fixed for a particular type of encryption. In this problem, we will be given a string and we have to encrypt it by following the given steps − First, we have to get all the substring that contains the same characters and replace that substring with a single character followed by the length of the substring. Now, change ... Read More

Count of 3 length strings using given characters containing at least 2 different characters

Prabhdeep Singh
Updated on 26-Jul-2023 10:27:26

67 Views

Three integers are given to us ‘a’, ‘b’, and ‘c’ represents the frequency of the three different characters ‘A’, ‘B’, and ‘C’. We have to find the number of different strings that can be formed by using these characters and there must be at least two different characters present in the string formed. We will see two approaches for this problem one is the naive approach and another is the mathematical approach. Sample Examples Input 1: a = 3, b = 2, c = 4 Output: 3 Explanation We can create three strings ‘ABC’, ‘ABC’, ... Read More

Maximize 0s to be flipped in a given Binary array such that there are at least K 0s between two 1s

Prabhdeep Singh
Updated on 26-Jul-2023 10:11:07

77 Views

A Binary Array is a special type of array that only contains the numbers 0 and 1. In this problem, we have given a binary array and integer K. Our task is to count the maximum number of 0’s that can be flipped to 1 in a given binary array such that there are at least K 0’s between two 1s. Sample Examples Input 1: arr[] = { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 }, K = 2 Output 1: yes Explanation The 3rd and 6th indexes of the above ... Read More

Print all Balanced Brackets Strings that can be formed by replacing wild card ‘?’

Prabhdeep Singh
Updated on 26-Jul-2023 10:08:53

118 Views

Balanced Brackets mean if we have a string of brackets then each open bracket has a corresponding close bracket and the pair of brackets is properly nested. The size of the string should be ab even number. In this problem we have given a string of the brackets that also contain the character ‘?’ and our task is to form every possible balanced bracket string by replacing the ‘?’ to appropriate brackets. In our given string only parentheses ‘(‘ and ‘)’ brackets are used. Sample Examples Input 1: str = “()(?)?” Output 1: ()(()) Explanation Only one balanced ... Read More

Check if the end of the given Binary string can be reached by choosing the jump value in between the given range

Prabhdeep Singh
Updated on 26-Jul-2023 10:00:09

33 Views

A binary string is a string that contains only two different types of characters that are 0 and 1. We are given a binary string and two integers L and the R. We can make the jump of size between ‘L’ and ‘R’ length both inclusive and only from the index where the value of the string is ‘0’. We have to start from the Zeroth index and find out whether we can reach the last index or not. Sample Examples Input1: string str = “01001110010” int L = 2, R = 4 Output: Yes, we can reach the ... Read More

Minimum K such that every substring of length at least K contains a character c

Prabhdeep Singh
Updated on 25-Jul-2023 15:21:05

113 Views

A string is given in this problem and we have to find a minimum length ‘k’ such that all the substrings of the given string of length k contains at least one common character. We will see three approaches for this problem, one the naive approach to find all the substrings, another one is the binary search approach and third is by using the minimum difference approach. Sample Example string str = “efabc” Output: 3 Explanation For the substrings of length 1 and 2 it is not possible to contain the same character for example substring ‘ef’ and ‘bc’ ... Read More

Kth Character After Replacing Each Character of String by its Frequency Exactly X Times

Prabhdeep Singh
Updated on 25-Jul-2023 15:18:22

103 Views

In this problem we have given a string ‘str’, integer K, and integer X. That string ‘str’ contains only integers in the range between 1 to 9. We have to perform an operation over the string exactly X times. Operation is that every time we have to replace a character of string by itself its frequency times. Here the frequency means the number or the value of the character of the string. Our task is to return the kth character after doing a given operation exactly X times. Sample Examples Input 1: str = “1231”, K = 5, X = ... Read More

Advertisements