public int ladderLengthII(String start, String end, Set<String> dict) {

		if (start.equals(end))
			return 2;

		LinkedList<String> word_queue = new LinkedList<>();
		LinkedList<Integer> distance_queue = new LinkedList<>();
		Set<String> visited = new HashSet<>();
		word_queue.add(start);
		distance_queue.add(1);
		visited.add(start);

		while (!word_queue.isEmpty()) {
			String word = word_queue.pop();
			int distance = distance_queue.pop();

			if (word.equals(end))
				return distance;

			for (int i = 0; i < word.length(); i++) {
				char[] chars = word.toCharArray();
				for (char c = 'a'; c <= 'z'; c++) {
					chars[i] = c;
					String newString = String.valueOf(chars);
					if (newString.equals(end) || dict.contains(newString) && !visited.contains(newString)) {
						word_queue.add(newString);
						distance_queue.add(distance + 1);
						visited.add(newString);
					}

				}
			}
		}
		return 0;
	}