public static Rectangle buildLargestRectangle(String[] words) {
        sortWordsByLength(words);
        int maxWordLength = words[0].length();
        int maxSize = maxWordLength * maxWordLength;
        ArrayList<String>[] wordGroups = createWordGroups(words);
        TrieNode[] trieGroups = new TrieNode[maxWordLength + 1];
        for (int size = maxSize; size > 0; --size) {
            for (int length = maxWordLength; length > 0; --length) {
                if (size % length == 0) {
                    int width = size / length;
                    if (width <= maxWordLength) {
                        createTrieGroups(wordGroups, trieGroups, width);
                        Rectangle result = buildRectangle(wordGroups, trieGroups, length, width);
                        if (result != null) return result;
                    }
                }
            }
        }
        return null;
    }