Found 1862 Articles for Data Structure

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

78 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

121 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

115 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

105 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

Convert given Strings into T by replacing characters in between strings any number of times

Prabhdeep Singh
Updated on 25-Jul-2023 15:16:19

57 Views

Convert string means we have to make the same as a given string on the basis of a given condition. In this problem, we have given an array of strings ‘arr’ and string ‘T’ of size ‘M’. our task is to check if is it possible to make all the string present in an array as same as the given string T by removing any character from a string of an array ( arr[i] ) and inserting that character into any index of another string of the array ( arr[j] ). We can do this any number of times. If ... Read More

Program to print binomial expansion series

Divya Sahni
Updated on 25-Jul-2023 15:08:27

294 Views

Binomial expansion is a mathematical formula used to expand the expressions of the form (a+b)^n, where n is a positive integer and a and b can be any real or complex numbers. The expansion gives the coefficients of the terms in the expansion. A binomial expansion can be represented as $$\mathrm{(a+b)^n= ^nC_0a^nb^0+ ^nC_1a^{n-1}b^1 + ^nCa^{n-2}b^2+...+ ^nC_ra^{n-r}b^r+...+ ^nC_na^0b^n}$$ where $\mathrm{^nC_r}$ are the binomial coefficients and is given by $\mathrm{^nC_r=\frac{n!}{r!\times(n−r)!}}$ where n! is the factorial of n The expansion can be used for calculating all the binomial terms using the formula above and putting it into the expansion equation. Problem ... Read More

Modify array of strings by replacing characters repeating in the same or remaining strings

Divya Sahni
Updated on 25-Jul-2023 13:28:25

129 Views

Modifying an array of strings by replacing characters repeating in the same or remaining strings is a common problem in programming. It can be solved using hash tables, sets, arrays etc. The aim is to improve the time and space requirements while providing the same functionality. This problem can be encountered in many real-life scenarios, such as processing large text or cleaning up datasets with duplicates. Problem Statement Given an input string array arr[] containing lowercase and uppercase characters. The goal is to modify the array by removing characters from the strings which are repeating in the same string or ... Read More

Advertisements