What’s the effective algorithm to find all sizes of the same units one row of letters wide that all 2d grid of characters is constructed from? Our grid and units may consist of all lowercase letters of the English alphabet. Our unit can be in horizontal or vertical position. The first line of output should contain a number of units k and next k rows. Each row contains the size of unit. Any suggestions or help would be greatly appreciated.
8 6 abaaab aabbaa bbabbb aababa bababb aaabab bbabaa ababbb
(Our grid can be constructed from one unit of size 2 –> "ab"):
But in case:
4 5 aaaaa aadaa aaaaa aaaaa
(we don’t have any such units)
Source: Windows Questions C++