Found 1862 Articles for Data Structure

The maximum length of string formed by concatenation having an even frequency of each character

Disha Gupta
Updated on 05-Feb-2024 18:11:07

52 Views

Concatenation is an operator which is used to join one or more than one string to originate a new string which would be a combination of strings that were used to generate it with the help of concatenation. In the following article, we will take the uppercase letters only in the input string. Concatenation is an operator which is used to join one or more than one string to originate a new string which would be a combination of strings that were used to generate it with the help of concatenation. In the following article, we will take the uppercase ... Read More

Maximize the String value by assigning values in the range [1, 26] to each character

Disha Gupta
Updated on 05-Feb-2024 18:14:07

147 Views

There are 26 total different alphabets exist in the English language. If we want to change the alphabet characters into numerical values then we need to assign the alphabet, values between 1 to 26 only. Now, in this problem, we need to Maximize the String value by assigning values in the range [1, 26] to each character. Let us see how we should proceed to solve this problem. Let’s try to understand this problem with the help of some examples. Input s = “blpsBpPtT” Output 221 Explanation Here, in this ... Read More

Find the next number by adding natural numbers in order on alternating indices from last

Disha Gupta
Updated on 05-Feb-2024 18:16:08

73 Views

A numerical string is used to store a value of a number if we want to store a huge valued integer. As we know, we can not store a number greater than 32 bits in the computer with its datatype as int. So to avoid the overflowing condition, in this problem, we will take a numerical string as our input rather than an int variable so that we can work this problem on a larger scale of numbers. Problem Statement Now, in this problem, we need to find the following number by adding natural numbers in order on alternating indices ... Read More

Count of substrings with the frequency of at most one character as Odd

Disha Gupta
Updated on 05-Feb-2024 18:19:37

222 Views

Substrings are the subsets or sequences of contiguous characters of a string. Now, in this problem, we need to find the number of substrings with the frequency of at most one character as odd. Let us see how we should proceed to solve this problem. Let’s try to understand this problem with the help of some examples. Input s = “ksjssjkk” Output 21 Explanation − As the frequency of the characters in the given string is given below− k → 3 s → 3 j → 2 Now, substrings with ... Read More

Check if two arrays of strings are equal by performing swapping operations

Disha Gupta
Updated on 22-Jan-2024 11:50:18

175 Views

The arrays of strings are a 2-dimensional array that stores characters in it. In C++ language we have an inbuilt function, with syntax − Syntax swap (first_datatype, second_datatype) which is used to perform swap operations on two elements, that is, exchange the values they carry. In the following, we are also supposed to do some exchange in positions of the elements of the string to get the expected output. However, we can get our output in a much easier way. Problem Statement Now, in this problem, we are provided with two arrays of strings (meaning arrays or ... Read More

Program to find the sum of series 1*2*3 + 2*3*4+ 3*4*5 + . . . + n*(n+1)*(n+2)

Disha Gupta
Updated on 05-Feb-2024 18:23:29

503 Views

The sum of the series is the value of all terms in the given series added together in a particular pattern. Here given pattern is in the form of the: ∑ (n*(n+1)*(n+2)) as (n*(n+1)*(n+2)) is the last term in the given pattern. The following article discusses 3 approaches in detail to find the given sum of the series with different time and space complexities. Problem Statement Now, let us see how to calculate the sum of series 1*2*3 + 2*3*4 + 3*4*5 + . . . + n*(n+1)*(n+2). Sample Examples Let’s try to understand this problem with the help ... Read More

Lexicographically largest possible by merging two strings by adding one character at a time

Disha Gupta
Updated on 22-Jan-2024 12:49:45

218 Views

Lexicographic means the algorithm by using which we can arrange given words in alphabetical order, the same concept which is used in dictionaries. The largest possible string that we would get by merging two strings taking one-character element at a time so that the order is lexicographic can be obtained by arranging alphabets in decreasing order or descending order keeping the sequence of elements in mind. Problem Statement Now, in this problem, we need to find lexicographically the largest possible string we get by merging two given strings. To understand this problem, we should know the basic concept we use ... Read More

Sort array of strings after sorting each string after removing characters whose frequencies are not a powers of 2

Shubham Vora
Updated on 10-Aug-2023 10:40:53

74 Views

In this problem, we need to remove the characters from the string whose frequency is not the power of 2. After that, we need to sort each string of the array in non-increasing order. Problem statement- We have given an array arr[] containing total N strings of different lengths. We need to remove the character from the string if its frequency is not the power of 2. After that, we need to sort each string Sample examples Input – arr[] = {"abde", "cpcc", "ddddd", "kk"} Output – edba, p, kk Explanation In the string ‘abde’ string, all characters' frequency is ... Read More

Reorder characters of a string to valid English representations of digits

Shubham Vora
Updated on 10-Aug-2023 10:39:25

43 Views

In this problem, we need to reorder the characters of a given string to valid English representations of digits. The first approach can be to find all permutations of the string, extract the English words related to numeric digits, and convert them to digits. Another approach that can be used to solve the problem is by finding one unique character from each word. In this tutorial, we will learn both approaches to solving the given problem. Problem statement- We have given a sting containing lowercase characters and a length equal to N. The string contains the English word representation of ... Read More

Reduce a string to a valid email address of minimum length by replacing specified substrings

Shubham Vora
Updated on 10-Aug-2023 10:36:28

45 Views

In this problem, we have given the email string containing the ‘dot’ and ‘at’ words. We need to replace them with ‘.’ And ‘@’ characters. Note – The valid email address should contain the ‘@’ character only once. It should contain any prefixes before the ‘@’ character and the domain name after that. Also, a valid email can contain multiple ‘.’ Characters. Furthermore, the ‘@’ and ‘.’ Characters should not be at the start or end of the email address. Problem statement – We have given a string str containing the email address, and the length of the string is equal ... Read More

Advertisements