How often does the letter i occur in:
Let us understand and solve this problem.
String 1: monday
String 2: tuesday
Common suffix: day
String 1: yo abc.
String 2: hey im abc.
Common suffix:  abc.
So, the simplest approach shall be to iterate both the strings from their last character and linearly compare characters one by one. We use two different iterators for the two strings, each one initialized with a different value. Let m and n be the iterators for str1 and str2.
Here, we see that the common suffix string ans is reversed before being returned. This is because as we traverse the strings backwards, the value in ans will be inverted. Example ,if str1= abcabcd and str2= defabcd
n points to the last character in str2 i.e. d.
Since, str1[m]==str[n], therefore, ans=d.
n points to the last second character in str2 i.e. c.
which is the reverse of the common suffix which is cd.
abcd will be returned as the final answer.
where n is the length of the shorter string.
If we want to scale this problem for more than two strings using this brute-force linear iteration approach, we will have to take the last letter from one of the strings, and compare it to the last letter of every other string. If all the strings have the same last letter, the s[s.size()-2] is checked for all strings. This continues on until a case where the letter varies in even a single case or one of the strings has reached its end. All common letters are appended to the answer string ans , which is later reversed and returned.
To keep track of the last indexes of all the strings given to us (in a vector<string> given), we create another vector. This vector can either contain the last index of the strings in the form of vector<int> or, we can maintain a vector of pointers of the type const_reverse_iterator where each value is initialized by given[i].crbegin() of the string. Then, on comparison, if the character is found to be common, the iterator is incremented using ++ operator.
Time complexity for this is O(n * m) where n is the number of strings in the vector given and m is the length of the shortest string.
Before we dive into this approach, we need a necessary understanding of what the Trie Data Structure is, as well as its working and implementation.
If a blank space   is encountered in a string, how will the trie process it?
The blank space will be given its own node and added as a key to the map.
The trie will skip the blank space and move on to the next character.
Every blank space will be given its own node.
We will also need to define the insert() function and a getnewnode() function for our trie, to insert the given strings into it.
We will add more code here for calling the common suffix function.
none of the strings have reached their end, i.e. endofword==false.
The letters which fulfil the conditions are added to our answer string ans.
The moment either of the conditions turn false, we shall stop the traversal, and return the string ans after reversing it.
We have our function ready. So, we edit the main function and call findcommonsuffix(). Lets take a final look at our entire code.
Using a trie for this problem reduces the time complexity to O(m) where m is the length of the shortest string, a reduction from the brute force approach, which was O(n * m).
However, the insertion of the strings in the trie takes O(n * m) where n is the number of words/strings and m is the average length of each string.
With this article at OpenGenus, you learnt the different ways you can approach and solve the longest common suffix problem. Keep learning!

user
I found two hundred and eight "i"s in the provided passage.
assistant