Sorry for not commenting, definitely something I need to work on. Thanks anyway, I finally got it.
--- Update ---
My code for anyone interested.
import java.util.HashMap;
import java.util.Map;
public class grafixCorrupt {
/*public static void main(String[] args){
String[] kj = {"double", "bobble", "bubble", "rubble", "hubble", "supple"};
String lag = "dimple";
System.out.println(selectWord(kj, lag));
}
*/
public static int selectWord(String[] dictionary, String candidate){
int max = 0;
boolean condition = false;
Map<Integer, Integer>matched = new HashMap<Integer, Integer>();
for(int i = 0;i<dictionary.length;i++){
matched.put(i, 0);
}
for(int i = 0;i<dictionary.length;i++){
int index = 0;
for(int j = 0;j<candidate.length();j++){
if(dictionary[i].substring(j,j+1).equals(candidate.substring(j,j+1))){
index++;
}
}
matched.put(i, matched.get(i)+index);
}
for(int i = 0;i<matched.size();i++){
if(i==0){
if(matched.get(i)>= matched.get(max)&& matched.get(i)>0){
max = i;
condition = true;
}
}else if(matched.get(i) > matched.get(max)){
max = i;
condition = true;
}
}
//System.out.println(matched);
//System.out.println(condition +":" + max);
if(max == 0 && condition==false){
return -1;
}else if(max==0 && condition==true){
return 0;
}
return max;
}
}
I think I overcomplicated this problem.