Programming Interview Question — Maximum Connected Area

Lintcode question #261 or Leetcode #695

Question Setup

There is a two-dimensional array, only consists of 00 and 11.

You can change a 0 to 1 at most once, please calculate the maximum area of connected 1s.

If two 1s are adjacent up to down or left to right, they are regarded connected.

Example

Input:

[[0,1]

,[1,0]]

Output:

3

Solution— Step by Step Visualised

Python Code

Happy coding!

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store