PROBLEM STATEMENT
Given an image made up of the colors A-Z, return the size (height * width) of
the smallest sized sub-image which could be used to tile it.
For illustrative purposes, XxY refers to a rectangle X pixels wide and Y pixels
high.
A tile is a sub-image which is repeated in a grid to form the original image.
The edges of the tile do NOT have to line up exactly with the right and bottom
edges of the original image, but every pixel in the image must match the tiling
scheme. (see the following example).
Let's say you were given the 7x3 image,
ABCABCA
DEFDEFD
ABCABCA
The smallest rectangle that could be used to tile it is
ABC
DEF
If you use spaces to show the breaks between tiles (purely illustrative), it
would be:
ABC ABC A
DEF DEF D
ABC ABC A
Note that the tile does not have to tile the image exactly; parts of it may end
off the edge, but every pixel in the image must match the tiling scheme, and
the tile's upper-left pixel should start at (0,0).
In this case, the tile is 3x2 and so your method would return 6.
Note that the tile layout will never be:
ABC ABC A
ABC ABC A
C ABC ABC
C ABC ABC
A tile is NOT valid if it must be staggered like this. (See example 5)
DEFINITION
Class: Pattern
Method: findTile
Parameters: String[]
Returns: int
Method signature (be sure your method is public): int findTile(String[] image);
NOTES
- if there is no valid tile smaller than the image, return the size of the image
TopCoder will ensure the validity of the inputs. Inputs are valid if all of
the following criteria are met:
- image will have between 1 and 50 elements, inclusive
- each element of image will have between 1 and 50 characters, inclusive
- each element of image will have the same length
- each element of image will consist of only the uppercase letters A-Z.
EXAMPLES
(1)
image: {"XXOOXXOO",
"XXOOXXOO",
"OOXXOOXX",
"OOXXOOXX"}
The smallest tile which could have been used to tile the image is 4x4:
XXOO
XXOO
OOXX
OOXX
so the method would return 16.
(2)
image: {"AAAAAAA",
"AAAAAAA",
"AAAAAAA",
"AAAAAAA",
"AAAAAAA"}
The smallest tile which could be used to tile the image is 1x1:
A
so the method would return 1.
(3)
image: {"AAAAAAAA",
"ABAAAABA",
"AAAAAAAA",
"AAAAAAAA",
"ABAAAABA"}
The smallest tile is:
AAAAA
ABAAA
AAAAA
so the method would return 5x3 = 15
(4)
image: {"ABC",
"DEF"}
The smallest tile is the image itself, so the method would return 3x2 = 6.
(5)
image: {"ABCABCA",
"ABCABCA",
"CABCABC",
"CABCABC"}
The smallest tile is
ABC
ABC
CAB
CAB
so the method would return 12.