public List<List<String>> findLadders(String a, String b, List<String> list) {
        Map<String, Set<String>> map = new HashMap<>();
        map.put(a, new HashSet<>());
        Queue<String> q = new LinkedList<>();
        for (String s : list) {
            addVertexAndEdge(s, map);
        }

        q.add(a);
        Map<String, Integer> d = new HashMap<>(); // distance
        d.put(a, 1);
        List<List<String>> lists = new ArrayList<>();
        boolean isFound = false;

        while (!q.isEmpty()) {
            String x = q.remove();
            for (String s : map.get(x)) {
                if (!d.containsKey(s)) {
                    d.put(s, d.get(x) + 1);
                    if (s.equals(b)) {
                        isFound = true;
                    } else {
                        q.add(s);
                    }
                }
            }
            if (isFound) {
                LinkedList<String> path = new LinkedList<>();
                dfs(b, a, map, d, lists, path);
                return lists;
            }
        }

        return lists;
    }
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