The is an easy implementation problem. You just need to find the upper left corner with a n*m loop.
And then run a loop through the row and count number of elements in counter1 and another through the column and count number of elements in counter2.
If (counter1==counter2), it is a Square, otherwise Rectangle.