private static int longestChain(String[] words) {
		if (words == null || words.length == 0) {
			return 0;
		}
		Map<Integer, Set<String>> lenWordsMap = new HashMap<Integer, Set<String>>();
		int longestChain = 0;
		int curLen = 0;
		for (int i = 0; i < words.length; i++) {
			int len = words[i].length();
			curLen = Math.max(curLen, len);
			if (lenWordsMap.containsKey(len)) {
				lenWordsMap.get(len).add(words[i]);
			} else {
				Set<String> wordSet = new HashSet<String>();
				wordSet.add(words[i]);
				lenWordsMap.put(len, wordSet);
			}
		}
		while (curLen > 0 && longestChain < curLen) {
			Set<String> wordInThisLevel = lenWordsMap.get(curLen);
			if (wordInThisLevel != null) {
				for (String word : wordInThisLevel) {
					longestChain = Math.max(longestChain,
							getChainLen(word, lenWordsMap));
				}
			}
			curLen--;
		}
		return longestChain;
	}