A : 1
A - A : 2
A - A - A : 3
A - A - A - A : 4
A - A - A - A - A : 5
A - A - A - A - E : 6
A - A - A - A - I : 7
A - A - A - A - O : 8
A - A - A - A - U : 9
A - A - A - E: 10
...
-> DFS
import java.util.*;
class Solution {
Map<String, Integer> map = new HashMap<>();
int count = 0;
public int solution(String word) {
dfs("");
return map.get(word);
}
private void dfs(String word) {
if (word.length() > 5) return;
map.put(word, count++);
for (int i = 0; i < 5; i++) {
dfs(word + "AEIOU".charAt(i));
}
}
}