Island Perimeter

Easy
Arrays Array Matrix

Given a grid (1=land, 0=water), calculate the island perimeter.

Constraints

1 ≤ rows, cols ≤ 100

Examples

Example 1:
Input: 0 1 0 0 1 1 1 0 0 1 0 0 1 1 0 0
Output: 16
Example 2:
Input: 1
Output: 4
▲ Console

Install Talent Arabia

Get instant access to jobs and career tools on your device.