Found 1862 Articles for Data Structure

Lexicographically Smallest String formed by Concatenating any prefix and its Mirrored form

Shubham Vora
Updated on 25-Aug-2023 16:57:58

105 Views

In this problem, we will find the lexicographically smallest string by concatenating the given string’s prefix and its reverse. We can find the lexicographically smallest prefix of the string and get the required string. Problem statement – We have given a string alpha containing the alphabetical characters. We need to construct the lexicographically smallest string, which we can get by concatenating any string prefix with its reverse. Sample examples Input alpha = "welcome"; Output 'wewe’ Explanation – The lexicographically smallest prefix is ‘we’. So, we have concatenated it with its mirror. Input alpha = "tutorialspoint" ... Read More

Find the Valid Integer from given String

Shubham Vora
Updated on 25-Aug-2023 16:56:51

90 Views

In this problem, we need to extract the integer from the given string by following the rules in the problem statement. We can solve the problem by checking if the initial substring of the string follows each rule given for the valid integer value. Problem statement – We have given string digits containing the numeric digits, ‘.’, ‘+’, and ‘-‘ characters. We need to extract the valid integer value from the given string. Rules for valid integers It should not contain the leading zeros and whitespaces. The integer should either start with a sign or digits. When any sign ... Read More

Find the String Among given Strings Represented using given Encryption Pattern

Shubham Vora
Updated on 25-Aug-2023 16:54:02

66 Views

In this problem, we need to find the original string from the encrypted string using the given encryption rules. We can get the original string if we use the encryption rules in reverse order. Problem statement – We have given an encrypted string. Also, we have given an array of strings containing multiple strings. We need to find the string from the array, so if we encrypt according to the below rules, we can get the encrypted string. Encryption rules The encrypted string should start with a positive integer, representing a number of uppercase letters in the original string. ... Read More

Find Largest Valued Even Integer which is a Non-Empty Substring of S

Shubham Vora
Updated on 25-Aug-2023 16:47:15

91 Views

In this problem, we need to find the largest even valued substring of the given string. The even string always contains the 2, 4, 6, 8, 0 at last. So, we can take all substrings of the given string, and if any substring is even and greater than the maximum substring, we can update the maximum substring value. Problem statement – We have given string str containing numeric digits only. We need to find the largest substring of the str, which is an even integer value. Sample examples Input str = "1234789" Output 123478 Explanation ... Read More

Encoding a Sentence into Pig Latin

Shubham Vora
Updated on 25-Aug-2023 16:38:23

154 Views

In this problem, we will convert the sentence into Pig Latin. We can append the first character of each word at the last and append ‘ay’ after that. We will see three approaches to convert the given sentence into the Pig Latine. The logic is we can append the first character at the end and remove it from the string. After that, we can append ‘ay’ to the word. Problem statement – We have given a string alpha containing multiple words. We need to encode the string into Pig Latin. Note – The Pig Latine is a word encryption ... Read More

Check if Words in given Sentence Occur based on the given Pattern

Shubham Vora
Updated on 25-Aug-2023 16:33:06

80 Views

In this problem, we need to check whether the string follows the given pattern. We can solve the problem by mapping each character to the word. If any character of the pattern maps more than one word, we can say that the string is not following the pattern. Problem statement – We have given a ‘pat’ string containing N characters and an ‘alpha’ string containing N words. The given task is to check whether the ‘alpha’ string follows the pattern of the ‘pat’ string. Note – We can say that the ‘alpha’ string follows the pattern when the word matches ... Read More

Shortest String formed by Concatenating String A x Times and B y Times such that n(A)\x = n(B)*y

Shubham Vora
Updated on 25-Aug-2023 16:09:10

69 Views

In this problem, we need to find the shortest string, which is a multiple of string A and string B. The problem is very similar to finding the LCM (Least common multiplier) of two numbers. We can find the LCM of both strings’ lengths and make both strings’ lengths equal to LCM by concatenating to itself. After that, we can compare the string to check if it is possible to get the shortest string which multiple of A and B. Problem statement – We have given string A and string B of different lengths. We need to find the shortest ... Read More

Python3 Program to Find Maximum number of 0s placed consecutively at the start and end in any rotation of a Binary String

Shubham Vora
Updated on 25-Aug-2023 16:04:27

70 Views

In this problem, we will write the Python code to count the maximum sum of consecutive zeros at the start and end of the string. The problem solution can be divided into two parts. The first part is finding all rotations of the string. The second part is finding the starting and ending consecutive zeros in all rotations of the binary string. Another way to solve the problem is that counting the maximum consecutive zeros can answer the problem. Problem statement – We need to find the total number of maximum consecutive zeros at the start and end ... Read More

Program to convert given Binary to its equivalent ASCII character string

Shubham Vora
Updated on 25-Aug-2023 15:53:18

274 Views

In this problem, we need to convert the binary string to the character string. We can convert the binary string to an ASCII number string first, and then we can convert the character string. Problem statement – We have given a binary string bin_str whose size is multiple of 8. We need to convert the binary string to the character string. Sample examples Input bin_str = "0110110001101010" Output 'lj' Explanation – The ‘01101100’ is equivalent to 108 in the decimal, which is equivalent to the ASCII value of the ‘l’. The ‘01101010’ equals 106, and ... Read More

Minimum Number of Insertions in given String to Remove Adjacent Duplicates

Shubham Vora
Updated on 25-Aug-2023 15:49:58

62 Views

In this problem, we will count the minimum number of characters we need to insert to remove all adjacent duplicate characters. To solve the problem, we need to count the total number of adjacent duplicate character pairs. Problem statement – We have given a string named str containing N alphabetical characters. We need to find the total number of different characters we require to add to the string such that the resultant string shouldn’t contain any adjacent duplicated characters. Sample examples Input str = "ccddrt" Output 2 Explanation – We need to insert one character ... Read More

Advertisements