
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 7197 Articles for C++

132 Views
In this problem, we will print the minimum number of characters that we need to remove from the start and end to make the count of ‘1’ and ‘0’ the same in the given string. If we find the largest substring with an equal number of ‘1’ and ‘0’, we can get the answer by subtracting the substring length from the given string’s length. We will use the prefix sum technique to find the largest substring having an equal number of ‘1’ and ‘0’. Problem statement − We have given the ‘bin_str’ binary string containing the N characters. We ... Read More

125 Views
In this problem, we will divide the given binary string into the K subsequences such that we can minimize the maximum absolute difference of count of ‘1’ and ‘0’ in the given string. The logic to solve the problem is to create a maximum pair of 0 and 1 in subsequences. So, we can get the minimum difference between each subsequence. Problem statement − We have given a bin_str binary string of length N. We have also given the positive integer K. We need to divide the given string into the K disjoint subsequences to minimize the maximum absolute ... Read More

106 Views
In this problem, we will find the maximum possible product of the first and last digits of the string by rotating the string multiple times. The naïve approach is that find all rotations of the string, take the product of the first and last character, and choose the maximum product as an answer. Another approach is to find the product of every adjacent pair of characters and choose the maximum product. Problem statement − We have given a string num containing the numeric digits. We need to find the maximum product of the first and last character of the given ... Read More

146 Views
In this problem, we need to convert the bin1 string to the bin2 string by replacing the second character of the bin1 string with the minimum or maximum of the first and second characters and removing the first character. As we need to remove the initial character, we need to ensure that the last len2 − 1 character are the same in both strings. Also, we need to ensure that we can get the first character of the second string by performing the given operation with the starting characters of the bin1 string. Problem statement − We have given bin1 ... Read More

220 Views
In this problem, we have given M queries, and after performing each query on the given string, we need to print the maximum length of the string having only the ‘ch’ character. We will use the tabulation method of dynamic programming to find the maximum possible length of the substring after replacing the at most K characters with the given character. Problem statement − We have given a string alpha of length N and que[] array containing M queries of type {K, ch}, where K is a positive integer, and ch is a character. It is given that for each ... Read More

256 Views
In this problem, we will find the maximum length of the subsequence such that it should contain the contiguous characters, and the frequency difference of all characters won’t differ more than K. We need to find all possible subsequences of the given string and check whether it contains every character continuously and maximum frequency difference to get the output. Problem statement− We have given a string alpha containing the lowercase alphabetical characters. Also, we have given the positive integer K. We need to find the maximum length of the subsequence of the given string such that it follows the below ... Read More

418 Views
In this problem, we will find the binary string of the given length having the same number of ‘01’ and ‘10’ subsequences. The naïve approach to solving the problem is to generate all binary strings of the given length and check whether it contains the same number of ‘10’ and ‘01’ subsequences using the dynamic programming technique. Another efficient approach is to prepare a binary string based on whether the given length is odd or even. Problem statement − We have given a positive integer ‘len’ which is greater than 2. The task is to find the binary string ... Read More

459 Views
In this article, we will explain the concept of rolling hash and find the longest common substring using binary search and rolling hash. We will also provide a C++ code implementation for the same. Rolling Hash of a String Problem Statement Algorithm to Find the Longest Common Substring C++ Code Implementation Time and Space Complexity Rolling Hash of a String Rolling hash is a cryptographic technique used to calculate the hash value of a string. In this, we ... Read More

95 Views
In this problem, we will find all unique characters of the string with their first index, which is present in the string, after incrementing all characters of the given string by K. For a problem solution, we can take each unique character of the given string. Next, we can update each character individually and check whether the updated character is present in the string and not updated to another character to get the answer. Problem statement − We have given a string alpha and positive integer K. We need to increment each character’s ASCII value of the given string by ... Read More

174 Views
In this problem, we will find each word of the string which comes after all words of the ‘words’ array. The first approach to solve the problem is to split the string into words and match elements of the words[] array with the string words. If we find words[] array’s element in the same order inside the string, we print the next word of the string. Another approach is to create a string of all elements of the words[] array. After that, we can find that string as a substring in the alpha string. If we find it as a ... Read More