115: Maximum square

Given a 2D matrix, the matrix contains 0 and 1, return maximum area of a square with ones

 

Example 1

Input:    0 0 1 0 0
          1 1 1 0 1
          0 1 1 1 1
          1 0 0 1 0

Output: 4

Example 2

Input:    0 0 1 0 1
          1 0 1 1 1
          0 0 1 1 1 
          1 0 1 1 1

Output: 9
Difficulty:Medium
Topic:Dynamic programming
Problem #:115