Partially Correct,
When there appears to be Z, the path returned is not correct.
still need to fix.
class Solution { public String alphabetBoardPath(String target) { String[] board= {"abcde", "fghij", "klmno", "pqrst", "uvwxy", "z"}; if(target ==null || target.length() ==0){ return null; } String out=""; int row = 0; int col = 0; for(int i =0; i<target.length();i++){ char key = target.charAt(i); if(i>0 && target.charAt(i)==target.charAt(i-1)){ out = out+"!"; continue; } for(int j =0; j< board.length;j++){ if(board[j].indexOf(key)!= -1){ row = j-row; col = board[j].indexOf(key)-col; if(row >0){ out = out + repeat("D",row); } else{ out =out +repeat("U",(-row)); } if(col>0){ out = out + repeat("R",col); } else { out = out +repeat("L", -col); } out=out+"!"; row =j; col = board[j].indexOf(key); break; } } } return out; } public String repeat(String a, int b){ String out =""; for(int i =0;i<b;i++) { out = out+a; } return out; } }