Found 1862 Articles for Data Structure

Modify a Sentence By Reversing Order Of Occurrences Of All Palindrome Words

Shubham Vora
Updated on 18-Jul-2023 17:27:29

94 Views

Problem Statement We have given a string str containing a total of N words. We need to find all palindrome words in the given string and create a new string by reversing the order of all palindrome words. Sample Examples Input str = ‘nayan was gone to navjivan eye hospital’ Output ‘eye was gone to navjivan nayan hospital’ Explanation The string contains three palindrome words: nayan, navjivan, and eye. We have reversed the order of all three words and kept all other words the same. Input ‘Hello, users! How are you?’ Output ‘Hello, users! How are you?’ ... Read More

Minimum Removals Required To Place All 0s Before 1s In a Binary String

Shubham Vora
Updated on 18-Jul-2023 17:25:35

126 Views

Problem Statement We have given binary string str, and we require to remove minimum characters from the string such that we can place all zeros before 1. Sample Examples Input str = ‘00110100111’ Output 3 Explanation Here, we can achieve output 3 in two ways. We can either remove arr[2], arr[3], and arr[5] or arr[4], arr[6], and arr[7] from the string. Input str = ‘001101011’ Output 2 Explanation We can remove arr[4] and arr[6] to place all zeros before 1. Input str = ‘000111’ Output 0 Explanation In the given str, all ... Read More

Minimum Number That Can Be Obtained By Applying '+' And '*' Operations On Array Elements

Shubham Vora
Updated on 18-Jul-2023 17:16:15

58 Views

Problem Statement We have given an array of length ‘N’ containing some positive integers. Also, we have given the string of length ‘N-1’ containing only ‘*’ and ‘+’ characters, where ‘*’ is a multiplication operator, and ‘+’ is an addition operator. We require to perform the arithmetic operation with array elements in such a way that we can get a minimum positive integer value. Sample Examples Input array = [1, 2, 3], str = “*+” Output 5 Explanation It is the resultant value of ((1*2) + 3). Input array = [3, 3, 3, 3], str = ‘*++’ ... Read More

Make a String Non-Palindromic By Inserting a Given Character

Shubham Vora
Updated on 18-Jul-2023 17:13:31

75 Views

Problem Statement We have given a string str and character c in the input. We need to insert the given character c in the string at the index so that we can convert the string to non-palindromic. If we can’t convert the string to non-palindrome, print ‘-1’. Sample Examples Input str = ‘nayan’, c = ‘n’ Output ‘nnayan’ Explanation There can be multiple output strings as we can insert ‘n’ at any index in the given string. So, the output string can be ‘nnayan’, ‘nanyan’, ‘naynan’, ‘nayann’, etc. Input str = ‘sss’, c = ‘s’ Output ‘-1’ ... Read More

Lexicographically Largest String With Sum Of Characters Equal To N

Shubham Vora
Updated on 18-Jul-2023 17:10:57

346 Views

Problem Statement We have given a positive integer num. We need to find the lexicographically largest string of lowercase alphabetical characters such that the sum of all characters of the string is equal to num. Here, ‘a’ = 1, ‘b’ = 2, ‘c’ = 3, ‘d’ = 4, …., ‘z’ = 26. We need to use the ‘z’ characters at the string's start to create the largest lexicographical string. At last, we need to use the last character according to the num % 26 value. Sample Examples Input num = 30 Output ‘zd’ Explanation The ‘zd’ is the ... Read More

Distinct Numbers Obtained By Generating All Permutations Of a Binary String

Shubham Vora
Updated on 18-Jul-2023 17:09:11

253 Views

Problem Statement We have given binary string str of length N. We need to find all permutations of the string, convert them to the decimal value, and return all unique decimal values. Sample Examples Input str = ‘1’ Output [1] Explanation All permutations of the ‘1’ is only ‘1’. So, the decimal value related to ‘1’ equals 1. Input str = ‘10’ Output [1, 2] Explanation The permutations of ‘10’ are only ‘01’ and ‘10’, equivalent to 1 and 2, respectively. Input ‘101’ Output [3, 5, 6] Explanation All possible permutations of ‘101’ are ... Read More

Count Intervals That Intersects With a Given Meeting Time

Shubham Vora
Updated on 18-Jul-2023 17:07:14

47 Views

Problem Statement We have given a two-dimensional array containing the pairs of starting and ending times for time intervals in the 12-hour format. Also, we have given string str in the 12-hour time format. We need to find a total number of intervals which included the time represented by str. Sample Examples Input arr[][2] = {{“12:02:AM”, “10:55:PM”}, {“12:51:AM”, “11:40:AM”}, {“01:30:AM”, “12:00:PM”}, {“11:57:PM”, “11:59:PM”}}, str = “2:30:AM” Output 3 Explanation The time “2:30:AM” intersects the first three intervals. Input arr[][2] = {{“01:02:PM”, “10:55:PM”}, {“01:30:AM”, “11:00:AM”}}, str = “11:30:PM” Output 0 Explanation The ... Read More

Check If a String Can Be Made Palindromic By Swapping Pairs Of Characters From Indices Having Unequal Characters In a Binary String

Shubham Vora
Updated on 18-Jul-2023 16:17:27

155 Views

Problem Statement We have given string str and a binary string B. The length of both strings is equal to the N. We need to check if we can make string str palindromic by swapping the characters of it multiple times at any pair of indices that contains unequal characters in string B. Sample Examples Input str = ‘AAS’ B = ‘101’ Output ‘YES’ Explanation We can swape the str[1] and str[2] as B[1] and B[2] are not equal. The final string can be ‘ASA’. Input str = ‘AASS’ B = ‘1111’ Output ‘No’ Explanation ... Read More

Create a string of specific length in C++

Shubham Vora
Updated on 18-Jul-2023 16:11:27

4K+ Views

In C++, the string is a collection of various alphanumeric and special characters. We can create a string using the ‘string’ data type in C++. Problem Statement We have given a length of the string and one single character, and we require to generate a string of a given length containing the single character. In C++, we can define the string of a particular length by hard coding the values, but when we require to generate a string of different lengths and use the given character, we require to use the below approaches. Sample Examples Here are the sample ... Read More

Check if uppercase characters in a string are used correctly or not

Shubham Vora
Updated on 18-Jul-2023 16:08:57

124 Views

Problem Statement We have given a string ‘str’, containing the alphabetical characters in uppercase or lowercase. We require to check if uppercase characters are used correctly in the string. Followings are the correct way to use uppercase characters in the string. If only the first character is in uppercase, the other characters are in lowercase. If all characters of a string are in lowercase. If all characters of the string are in uppercase. Sample examples Input "Hello" Output "valid" Explanation In "Hello", only the first character is in uppercase, and others are in lowercase, so it ... Read More

Advertisements