Found 7197 Articles for C++

Count occurrences of substring X before every occurrence of substring Y in a given string

Shubham Vora
Updated on 18-Aug-2023 14:42:17

238 Views

In this problem, we need to count the total occurrences of the substring X in the str when we find the substring Y in the given string. We can keep counting the occurrences of the substring X, and when we get the substring Y, we can print the count value. Problem statement – We have given a string str, X, and Y. The length of the strings is N, A, and B, respectively. We need to total the total number of substring X in the given string str before every occurrence of the substring Y. Sample examples Inputstr = "stuxystuxy"; ... Read More

class std::string_view in C++17

Shubham Vora
Updated on 18-Aug-2023 14:41:14

268 Views

C++ contains many precious features to enhance the performance of the code, and string_view class is one of them. It is introduced to create a lightweight and non-owning reference to a string. In this tutorial, we will discuss the string_view class and explore a few examples using the string_view class over the string class in C++. What is string_view? The string_view is a class in C++ that is used to create a read-only sequence of the string. It is a non-owning string type, meaning it does not manage the memory associated with the string and its reference. It acts as ... Read More

Check if it is possible to obtain a Balanced Parenthesis by shifting brackets to either end at most K times

Shubham Vora
Updated on 18-Aug-2023 14:37:31

201 Views

In this problem, we need to check whether we can get the valid balanced subsequence of the parenthesis by moving at most K characters of the string at the end. To solve the problem, we can use the stack data structure. The logic to solve the problem is that if we find more than K ‘)’ (closing parenthesis) before the ‘(‘ (opening parenthesis), we can’t make a string into a valid subsequence. Problem statement – We have given string str containing the ‘(‘ and ‘)’ sequence of parenthesis. The length of the string is N. Also, We have given a ... Read More

Check if 2 * K + 1 non-empty strings exists whose concatenation forms the given string

Shubham Vora
Updated on 18-Aug-2023 14:32:51

115 Views

In this problem, we have given a string, and we need to divide the string into k + 1 substrings such that the concatenation of k + 1 substrings with their reverse can give us the original string. Observation can solve the problem. If the string's first and last k characters are the same, we can say it is possible to create a k + 1 string according to the given condition. Problem statement – We have given a string of length N containing the lowercase alphabetical characters and positive integer K. We need to find whether we can ... Read More

Find Last Palindrome String in the given Array

Shubham Vora
Updated on 17-Aug-2023 19:00:20

171 Views

In this problem, we need to find the last palindrome string in the array. If any string is the same in reading, either we start to read from the start or end, we can say the string is a palindrome. We can compare the starting and ending characters to check whether the particular string is palindromic. Another way to find the palindromic string is to reverse the string and compare it with the original string. Problem statement – We have given an array of length N containing the different strings. We need to find the last palindrome string in the ... Read More

Find any permutation of Binary String of given size not present in Array

Shubham Vora
Updated on 17-Aug-2023 17:48:54

242 Views

In this problem, we need to find all missing binary strings of length N from the array. We can solve the problem by finding all permutations of a binary string of length N and checking which permutations are absent in the array. Here, we will see iterative and recursive approaches to solve the problem. Problem statement – We have given an array arr[] of different lengths containing the binary strings of length N. We need to find all the missing binary strings of length N from the array. Sample examples Input – arr = {"111", "001", "100", "110"}, N = ... Read More

Count of substrings containing exactly K distinct vowels

Shubham Vora
Updated on 17-Aug-2023 17:46:47

319 Views

In this problem, we need to count the total number of substrings of string str containing exactly K distinct vowels. We can solve the problem in two different ways. The first approach is to traverse all substrings and count the number of vowels in each substring. We can also use the map data structure to optimize the code of the first approach. Problem statement – We have given string str of length N. The string contains uppercase and lowercase alphabetical characters. Also, we have given integer K. We need to find the total number of substrings of str containing exactly ... Read More

Count of K length substrings containing exactly X vowels

Shubham Vora
Updated on 17-Aug-2023 17:44:40

208 Views

In this problem, we need to find a total number of substrings of length K containing exactly K vowels. We will see two different approaches to solving the problem. We can use a naïve approach that checks the number of vowels in each substring of length K. Also, we can use the sliding window approach to solve the problem. Problem statement – We have given a string str of length N containing lowercase and uppercase alphabetical characters. We need to count the total number of substrings of length K which contains exactly X vowels. Sample examples Input– str = ... Read More

Check if substring S1 appear after any occurrence of substring S2 in given sentence

Shubham Vora
Updated on 17-Aug-2023 17:42:43

387 Views

In this problem, we need th check whether the substring S1 appears after any occurrence of the substring S2 in the given string S. We can compare the starting index of S1 and S2 in the string S to solve the problem. Problem statement – We have given three substrings named S, S1, and S2. The string S always contains S1 as a substring. We need to check whether the substring S1 appears after any occurrence of the substring S2 in the given string S. Sample examples Input – S = "abxtutorialspointwelcomepoint", S1 = "welcome", S2 = "point"; ... Read More

Check if any permutation of a given string is lexicographically larger than the other given string

Shubham Vora
Updated on 17-Aug-2023 17:39:46

183 Views

We have given two strings and need to check whether the given string's permutations exist such that one permutation can have a larger character than another permutation at the ith index. We can solve the problem by sorting the string and comparing each character of the string one by one. Also, we can solve the problem using the frequency of characters of both strings. Problem statement – We have given a string str1 and str2 of length N. We need to check whether any permutations of both strings exist such that the permutation of one string is lexicographically larger than ... Read More

Advertisements