Optimized Identifiers
In an Amazon inventory management, an operations analyst is dealing with a set of initial product identifiers represented by strings. The type of a string product identifier is determined by the first and last letters in the identifier string, for example, the type of the identifier string "abddaac" is "ac".
The analyst wants to optimize the product identifiers by performing a series of operations on the string to maximize the number of operation between the final and initial types. Given a product identifier string s, the analyst can perform one operation at a time, involving the removal of either the first or last letter from the string.
Find the maximum number of operations they can perform on the string while ensuring that its type aligns with the initial string's type.
Note: The type of an empty string" is", and the type of a string with a single character, like "a", is "aa".
Complete the function optimizedIdentifiers in the editor below.
optimizedIdentifiers has the following parameter:
- 1.
string s: the initial product identifiers.
Returns
int: the maximum number of operations the operations analyst can perform on the string, such that its type is equal to the initial string's type.
1Example 1
2Example 2
3Example 3
Constraints
Limits and guarantees your solution can rely on.