public static int ladderLength(String start, String end, Set<String> dict) {
    	if (dict.size() == 0)
    		return 0;
    	
    	Queue<String> wordsQueue = new LinkedList<String>();
    	Queue<Integer> distanceQueue = new LinkedList<Integer>();
    	
    	wordsQueue.add(start);
    	distanceQueue.add(1);
    	dict.add(end);
    	
    	while (!wordsQueue.isEmpty()) {
    		String currentWord = wordsQueue.poll();
    		Integer currentDistance = distanceQueue.poll();

    		if (currentWord.equals(end))
    			return currentDistance;
    		
    		for (char c = 'a'; c <= 'z'; c++) {
    			for (int i = 0; i < currentWord.length(); i++) {
    				char[] word = currentWord.toCharArray();
    				word[i] = c;
    				String newWord = new String(word);
    				if (dict.contains(newWord)) {
    					wordsQueue.add(newWord);
    					distanceQueue.add(currentDistance + 1);
    					dict.remove(newWord);
    				}
    			}
    		}
    	}
    	
    	return 0;
    }