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: 
JavaScript, 92 bytes
====================

```
a=>(g=w=>a.match(Array(w).fill(`1{${w}}`).join(`..{${W-w}}`))?w*w:g(w-1))(W=a.indexOf`,`)||1

```

```js
f=
a=>(g=w=>a.match(Array(w).fill(`1{${w}}`).join(`..{${W-w}}`))?w*w:g(w-1))(W=a.indexOf`,`)||1
console.log(f('0111,1111,1111,1111'));
console.log(f('10100,10111,11111,10010'));
console.log(f('0111,1101,0111'));
```
[Perl 6](https://github.com/nxadm/rakudo-pkg), ~~61~~ ~~60~~ 58 bytes
=====================================================================

```perl6
{(^$_ X.. ^$_).max({[~&](.[|$^r||*])~~/$(1 x$r)/&&+$r})²}

```

[Try it online!](https://tio.run/##K0gtyjH7n1upoJamYPu/WiNOJV4hQk9PAUhr6uUmVmhUR9epxWroRdeoxBXV1GjFatbV6atoGCpUqBRp6qupaasU1Woe2lT7vzixUiFNQ6@4ICezRENdR11TUyEtv4hLydDA0MBAB0gaGuoYGoJJA6CQkg6XElwMQSAJGxjqgFhK1v8B "Perl 6 – Try It Online")