![]() |
VOOZH | about |
Given string str containing lowercase English characters, we can perform the following two operations on the given string:
The task is to find the maximum number of operations required to delete the entire string.
Examples:
Input: str = "abababab"
Output: 4
Explanation:
Operation 1: Delete prefix "ab" and the string becomes "ababab".
Operation 2: Delete prefix "ab" and the string becomes "abab".
Operation 3: Delete prefix "ab", str = "ab".
Operation 4: Delete the entire string.Input: s = "abc"
Output: 1
The idea is to store all possible length deletion of 2nd operation for every index of the given string and explore every possible deletion on each index and return the maximum operation among them.
Follow the step below to implement the above idea:
Below is the implementation of the above approach:
4
Time Complexity: O(N2)
Auxiliary Space: O(N)