Your challenge today is to take a multiline string, and output the biggest square contained within the string that includes the top left corner.
A square string is one where:
- Each line has the same number of characters
- The number of characters on each line is equal to the number of lines.
Consider the following possible input string:
abcde
fgh
asdf
foobar
The largest square you can take from it that includes the first character (the a
in the topleft corner) is this:
abc
fgh
asd
There can't be a square of side-length 4, because the second line isn't long enough. Now consider this potential input:
a
bcd
edf
ghi
The biggest square here is just a
. The 3x3 square formed in the bottom doesn't contain the very first character, and doesn't count.
Here's a few more test cases:
a
a
abc
def
gh
ab
de
ab
cd
ab
cd
abcde
fghij
klm
no
abc
fgh
klm
a
b
a
You may require input to be delimited by your choice of LF, CR, or CRLF.
The newline character(s) are not considered part of the line's length.
You may require there to be or to not be a trailing newline in input, which doesn't count as an additional line.
Input is a string or 1D char array; it is not a list of strings.
You may assume input is non-empty and all lines are non-empty, and that it only contains printable ASCII, including spaces and newlines (for the line delimiter) but not tabs.
This is code-golf, fewest bytes wins!
.split('\n')
so I don't see why some should get it for free. \$\endgroup\$