private boolean canBeConnected(String key, String s) {
        int diff = 0;
        for (int i = 0; i < key.length(); i++) {
            if (key.charAt(i) != s.charAt(i)) diff++;
            if (diff > 1) return false;
        }

        return diff == 1;
    }
to all shortest paths, i first used bfs to find distance from source to target and, from target to source i did dfs
src/problems/hard/WordLadder2.java