- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 7346 Articles for C++
217 Views
Problem Statement We have given a string str containing the numeric and alphabetical characters. We need to find the sum of all numbers represented by a continuous sequence of digits available in the given string. Sample Examples Input str = “12were43” Output 55 Explanation The sum of 12 and 43 is equal to 55. Input str = “1a2c3d” Output 6 Explanation The sum of 1, 2, and 3 is 6. Input str = “werderfrewsf” Output 0 Explanation It gives 0 in the output as the string contains no digit. Our logic to solve the ... Read More
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
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
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
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
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
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
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
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
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