Get Min Move π±
An English lecture at HackerElementary School is aimed at teaching students the letters of alphbets.
The students are provided with a string word that consists of lowercase English letters. In one move, the can choose any
index i, and let the character at the index be c. Then, the first occurrence of c to the left of i, and the first
occurence of c to the right of i are deleted (Note: the operation can still be carried out even if either the left or right
occurrence does not exist).
For example, if word = "adabacaea", and if index 8 is chosen (0-based), the
first occurrence of 'a' to the left and right of index 4 (bold, indices 2 and 6) are deleted leaving word = "adbacea".
Find the min num of moves the students need to perform in order to get a word of minimal length.
Complete the function getMinMove in the editor below.
getMinMove has the following parameter(s):
String word: the word given to the studentsReturns
int: the min num of moves needed to get a word of minimal length
1Example 1
2Example 2
Constraints
Limits and guarantees your solution can rely on.
1 <= |word| <= 105