Hi all,

I tried to solve this problem using backtracking as an exercise.

What do you think?

```
public class Solution {
public int minMutation(String start, String end, String[] bank) {
if(start.length()!=end.length()) return -1;
if(start==end) return 0;
Set<String> set = new HashSet<>();
int min = Integer.MAX_VALUE;
for(String s: bank){
if(dist(start,s)>1) continue;
set.add(s);
min = Math.min(min, minMutation(s,end,bank,set,0));
set.remove(s);
}
if(min==Integer.MAX_VALUE) return -1;
return min;
}
public int minMutation(String current, String end, String[] bank, Set<String> set, int depth){
if(current.equals(end)) return 1;
int min = Integer.MAX_VALUE;
if(depth>=end.length()) return min;
for(String s: bank){
int diff=dist(current,s);
if(!set.contains(s) && (diff==1)){
set.add(s);
int num = minMutation(s,end,bank,set,depth+1);
min = Math.min(min, num);
set.remove(s);
}
}
if(min==Integer.MAX_VALUE)
return min;
return 1+min;
}
// counts the distance between two strings
public int dist(String start, String end){
if(start.length()!=end.length()) return Integer.MAX_VALUE;
int diff = 0;
for(int i=0; i<start.length(); i++){
if(start.charAt(i)!=end.charAt(i)) diff++;
}
return diff;
}
}
```