Strings
Explore key string concepts in competitive programming using C++. Understand anagrams, substrings, subsequences, and palindromes through detailed explanations and examples to enhance your problem-solving skills.
We'll cover the following...
String
A string is a sequence of characters; hence it can be represented using an array of characters.
C++ also has a string type that can be used instead of char[].
First, let’s go over some common terms used in programming competitions for strings.
Anagram
The anagram of a string is obtained by rearranging the letters in the string.
For example: evil is an anagram of live, other anagrams are leiv and vile.
Whereas lie is not because we removed v.
Substring
Substring is a contiguous sequence of characters within a string. Analogous to subarray in arrays.
For example: for the string competitive
comp, tive, and pet are substrings. cope is not because it’s not contiguous in competitive.
Correspondingly, there are ...