private static Rectangle buildRectangleByRow(ArrayList<String> cadidateWords, TrieNode trie, Rectangle rectangle, int runningWidth) {
        if (runningWidth == rectangle.getWidth()) {
            if (isCompleteRectangle(trie, rectangle)) {
                return rectangle;
            } else {
                return null;
            }
        }
        if (!isPartialRectangle(trie, rectangle)) {
            return null;
        }
        for (String word : cadidateWords) {
            rectangle.append(word);
            Rectangle result = buildRectangleByRow(cadidateWords, trie, rectangle, runningWidth + 1);
            if (result != null) return result;
            rectangle.remove(); // restore state
        }
        return null;
    }