Get Min Move π±
Learn this problemProblem statement
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.
Function
getMinMove(word: String) β int
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
Examples
Example 1
word = "baabacaa"return = 3Example 2
word = "cbaa"return = 1Constraints
1 <= |word| <= 105More IBM problems
- Parent Process NumberOA Β· Seen Jul 2026
- Request Retry CountOA Β· Seen Jul 2026
- Count Strictly Increasing Subsequences of Length 3OA Β· Seen Jul 2026
- Maximum Requests in a Time WindowOA Β· Seen Jul 2026
- Query Type Frequency WindowOA Β· Seen Jul 2026
- Minimum Number of Non-Empty Disjoint SegmentsOA Β· Seen Jul 2026
- Spam Text ClassificationOA Β· Seen Jul 2026
- Count Ideal NumbersOA Β· Seen Jun 2026