Company: Sharechat_15oct
Difficulty: medium
Minimum Length Word Problem Description An introductory language class focuses on helping students master the alphabet. Each student is given a string, word , made up of lowercase English letters. In a single move, a student picks an index i and a letter c ; if the character sitting at that index equals c , then the nearest occurrence of c to the left of i and the nearest occurrence of c to the right of i are both deleted, whenever they exist. For instance, if word = "adbacaca" and index 4 (character 'a') is chosen, the nearest 'a' to the left and right of index 4 (indices 2 and 6) get deleted, leaving word = "adbaca" . Determine the fewest moves a student needs to shrink the word down to its minimum possible length. Examples Example 1: Input: word = "baabacaa" Output: 3 Explanation: The following moves are optimal. Pick index 0 (character 'b'). The nearest 'b' to its right sits at index 3, and there is no 'b' to its left. Deleting the character at index 3 gives "baacaa" . From "baacaa