Programming Articles

Page 320 of 2544

class std::string_view in C++17

Shubham Vora
Shubham Vora
Updated on 18-Aug-2023 390 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
Shubham Vora
Updated on 18-Aug-2023 263 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
Shubham Vora
Updated on 18-Aug-2023 161 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

Minimum Cost to Modify a String

Sonal Meenu Singh
Sonal Meenu Singh
Updated on 18-Aug-2023 424 Views

Introduction In this tutorial, we use C++ programming concepts to implement examples to find the minimum cost to modify a string. String modification includes operations to change one string into another string. String operations include insertion, deletion, and substitution. We predefined the cost of each operation. You can choose the cost values of your choice. Generate output by calculating the total operation cost for string modification. The insertion function is used to insert missing characters, deletion is used to remove unwanted characters, and the substitution operation is used to replace a character with another character. For implementing the above ...

Read More

Maximum Length Palindrome of a String that can be Created with Characters in Range L and R

Sonal Meenu Singh
Sonal Meenu Singh
Updated on 18-Aug-2023 258 Views

Introduction A palindrome is one that reads the same forward and backward. An example of a palindrome string is Mam. In this tutorial, we use C++ programming to find the maximum length palindrome of a string by predefining the range of characters. Our task is to find the largest length of a palindrome string using the input string. We define the range of characters to generate that string. Depending on the situation, L and R can hold any value. Demonstration 1 String = “amem” Range = {1, 4} Output 3 In the above demonstration, the ...

Read More

Longest substring of only 4’s from the first N Characters of the Infinite String

Sonal Meenu Singh
Sonal Meenu Singh
Updated on 18-Aug-2023 179 Views

Introduction In this tutorial, we implement an approach to find the longest substring of only 4 using the first N characters of the infinite string. Infinite string using 4 looks like this: “44444444……” and for this string we define the length of characters to consider for solving the task. To solve the problem of this tutorial, consider an input numerical string, We solve this problem using two conditions and those conditions are as follows: Consider an input string with random digits and generate the longest substring of 4’s from the string. We consider an infinite string of combinations of ...

Read More

Introduction to the Probabilistic Data Structures

Sonal Meenu Singh
Sonal Meenu Singh
Updated on 18-Aug-2023 2K+ Views

Introduction In this tutorial, we will discuss probabilistic data structures in detail. This tutorial will cover the meaning of a Probabilistic Data Structure, its types, and its benefits. When dealing with large data sets or Big Data, basic data structures that use hashtables or HashSets would not be effective enough. As the data size increases, memory requirements increase with limited time for solving a query which restricts the functionality of deterministic basic data structures. Probabilistic data structures are approximate data structures that are collections of data structures. They are called so because they do not provide exact values. They ...

Read More

Given a String and an Integer k, find the kth Substring when all the Substrings are Sorted According to the given Condition

Sonal Meenu Singh
Sonal Meenu Singh
Updated on 18-Aug-2023 272 Views

Introduction In this tutorial, we implement an approach to find the kth substring after sorting all the substrings according to some conditions for a given string and the value of k. The condition to sort the substring is that the substrings are alphabetical while producing the substring in the order of their occurrence of each character in the alphabet. The first alphabet generates all its substrings, then the second alphabet produces all its substrings, and so on. Consider an example: the input string is “abc”, the alphabetically sorted substrings are “a”, “ab”, “abc”, “b”, “bc”, “c”. Predefined the value of ...

Read More

Generate all Permutations of a String that follow given Constraints

Sonal Meenu Singh
Sonal Meenu Singh
Updated on 18-Aug-2023 595 Views

Introduction In this tutorial, we implement two examples using C++ programming concepts to generate all permutations of an input string. Permutation of a string is the number of ways a string can be arranged by interchanging the position of characters. We also include some constraints or limitations. All permutations or arrangements of the input string ensure character B does not follow character A anywhere, meaning there is no AB combination in the string. To implement this task we use two approaches: Directly generate all combinations of the string while restricting AB. Using backtracking. Demonstration 1 String = ...

Read More

Capitalize the First and Last Character of Each Word in a String

Sonal Meenu Singh
Sonal Meenu Singh
Updated on 18-Aug-2023 642 Views

Introduction In this tutorial, we implement an approach to capitalizing the first and last characters of each word in the input string. By iterating over the input string str, each word's starting and ending letters are capitalized. We implement this problem using C++ programming in two ways. Let's start this tutorial with some demonstrations. Demonstration 1 String = “coding world” Output CodinG WorlD In the above demonstration, consider the input string and the result after capitalizing the starting and ending character of each word of the string is CodinG WorlD. Demonstration 2 String = “`hello all” ...

Read More
Showing 3191–3200 of 25,433 articles
« Prev 1 318 319 320 321 322 2544 Next »
Advertisements