scala twoliner with prefix sum
scala\nobject Solution {\n  def largest1BorderedSquare(grid: Array[Array[Int]]): Int = {\n    lazy val (px,py) = (grid.transpose.map(_.scanLeft(0)(_ + _)).trans
```scala\nobject Solution {\n  def largest1BorderedSquare(grid: Array[Array[Int]]): Int = {\n    lazy val (px,py) = (grid.transpose.map(_.scanLeft(0)(_ + _)).transpose, grid.map(_.scanLeft(0)(_ + _)))\n    (for{\n      sz <- (grid.size min grid.head.size) to 1 by -1\n      i  <- (0 to grid.size-sz)\n      j  <- (0 to grid.head.size-sz)\n    } yield {Option.when(Seq(\n        px(i+sz)(j)-px(i)(j), px(i+sz)(j+sz-1)-px(i)(j+sz-1),\n        py(i)(j+sz)-py(i)(j), py(i+sz-1)(j+sz)-py(i+sz-1)(j)\n      ).sum == 4*sz)(sz*sz)\n    }).flatten.headOption.getOrElse(0)\n  }\n}\n```
['Matrix', 'Prefix Sum', 'Scala']