Company: Sharechat_15oct
Difficulty: medium
Minimum Length Word Problem Description An English lecture at Hacky/Elementary School focuses on teaching students the letters of the alphabet. Students receive a string, word , composed of lowercase English letters. In one move, they can choose any index i and letter c . If the character at this index is c , then the first occurrence of c to the left and right of i are deleted if they exist. For example, if word = "adbacaca" and index 4 (character 'a') is chosen, the first occurrence of 'a' to the left and right of index 4 (indices 2 and 6) are deleted, resulting in word = "adbaca" . Determine the minimum number of moves required for the students to achieve a word of minimal length. Examples Example 1: Input: word = "baabacaa" Output: 3 Explanation: The following moves are optimal. Choose index 0 (character 'b'). The first 'b' to its right is at index 3. No 'b' to its left. Deleting the character at index 3 results in "baacaa" . From "baacaa" , choose index 2 (character 'a'). The firs