Question: This question is similar to [Biggest Square in a grid](https://codegolf.stackexchange.com/questions/152305/biggest-square-in-a-grid).

**Challenge**

Given a matrix of `1` and `0` in a string format `"xxxx,xxxxx,xxxx,xx.."` or array format `["xxxx","xxxx","xxxx",...]`, You will create a function that determines the area of the largest square submatrix that contains all `1`.

A square submatrix is one of equal width and height, and your function should return the area of the largest submatrix that contains only `1`.

**For Example:**

Given `"10100,10111,11111,10010"`, this looks like the following matrix:

1 0 1 0 0

1 0 1 **1 1**

1 1 1 **1 1**

1 0 0 1 0 

You can see the bolded `1` create the largest square submatrix of size 2x2, so your program should return the area which is 4.

**Rules**

* Submatrix must be one of equal width and height
* Submatrix must contains only values `1`
* Your function must return the area of the largest submatrix
* In case no submatrix is found, return `1`
* You can calculate the area of the submatrix by counting the number of `1` in the submatrix

**Test cases**

**Input:** `"10100,10111,11111,10010"` **Output:** `4`

**Input:** `"0111,1111,1111,1111"` **Output:** `9`

**Input** `"0111,1101,0111"` **Output:** `1`

---

This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the shortest answer in bytes win.

Answer: 
[APL (Dyalog Classic)](https://www.dyalog.com/), ~~21~~ 20 bytes
================================================================

```apl
×⍨{1∊⍵:1+∇2×/2×⌿⍵⋄0}

```

[Try it online!](https://tio.run/##SyzI0U2pTMzJT9dNzkksLs5M/v@ob2pm/qO2CQb/04Dk4emPeldUGz7q6HrUu9XKUPtRR7vR4en6QPyoZz9Q6FF3i0Ht//8lQKXVIG7nwiIgM@1R7y4r9fxsdaC0elpiZo46UAAoXVTLpfGot@/QikdtE9UNDQwNDNQVQLShIYg2hNIGQAl1zRIFEyTFSGrQKKBCS2wKDUCUAVSFIQA "APL (Dyalog Classic) – Try It Online")
Clojure, 193 bytes
------------------

```
#(apply max(for [f[(fn[a b](take-while seq(iterate a b)))]R(f next %)R(f butlast R)n[(count R)]c(for[i(range(-(count(first R))n -1)):when(apply = 1(for[r R c(subvec r i(+ i n))]c))](* n n))]c))

```

Wow, things escalated :o

Less golfed:

```
(def f #(for [rows (->> %    (iterate next)    (take-while seq)) ; row-postfixes
              rows (->> rows (iterate butlast) (take-while seq)) ; row-suffixes
              n    [(count rows)]
              c    (for[i(range(-(count(first rows))n -1)):when(every? pos?(for [row rows col(subvec row i(+ i n))]col))](* n n))] ; rectangular subsections
          c))

```