largest possible rectangle of letters

后端 未结 3 994
故里飘歌
故里飘歌 2021-02-01 10:04

Write a program to find the largest possible rectangle of letters such that every row forms a word (left to right) and every column forms a word (top to bottom).

3条回答
  •  遇见更好的自我
    2021-02-01 10:14

    Create a Bag[] for word of the same length = index then create an array of Tries, one Trie for wordList of each length

       Rectangle makeRectangle(length, height, rectangle)
        {
            if ( length == rectangle.length()) check if complete and return;
            checkIfPartialComplete - check columns for valid prefixes
            for ( i from 1 to grouplist[i-1])
            {
                newRectangle = append word[i] to rectangle 
                return makeRectangle(l,h, rectangle with appended word) if not equal to null
            }
        }
    
    
    boolean checkPartial(int l, Trie trie)
    {
        for ( int i =0 ; i < l; i++)
        {
            String col = getColumn(i);
            if (!trie.contains(col))
            {
                return false;
            }
        }
        return true;
    }
    boolean checkComplete(int l, Bag lengthGroup)
    {
        for ( int i=0; i < l ; i++)
        {
            String col = getColumn(i);
            if (!lengthGroup.contains(col))
            {
                return false;
            }
        }
        return true;
    }
    

提交回复
热议问题