PracHub
QuestionsPremiumLearningGuidesInterview PrepNEWCoaches
|Home/Coding & Algorithms/Snapchat

Compute maximum perimeter among islands

Last updated: Mar 29, 2026

Quick Overview

This question evaluates a candidate's proficiency with grid traversal, connected-component identification, and perimeter computation in binary matrices, reflecting skills in array/graph processing and spatial reasoning.

  • medium
  • Snapchat
  • Coding & Algorithms
  • Software Engineer

Compute maximum perimeter among islands

Company: Snapchat

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

## Problem You are given an `m x n` binary grid `grid` where: - `grid[r][c] = 1` represents land - `grid[r][c] = 0` represents water An **island** is a maximal set of land cells connected **4-directionally** (up, down, left, right). The **perimeter** of an island is the total number of unit edges of land cells that either: - lie on the boundary of the grid, or - border a water cell. Return the **maximum perimeter** among all islands in the grid. If there is no land, return `0`. ## Input / Output - **Input:** `grid: List[List[int]]` - **Output:** `int` (maximum island perimeter) ## Constraints (typical interview constraints) - `1 <= m, n <= 1000` (or similar) - `grid[r][c]` is `0` or `1` - Aim for `O(mn)` time ## Example Given: ``` grid = [ [0,1,1,0], [0,1,0,0], [1,1,0,0] ] ``` There are two islands; return the larger island’s perimeter.

Quick Answer: This question evaluates a candidate's proficiency with grid traversal, connected-component identification, and perimeter computation in binary matrices, reflecting skills in array/graph processing and spatial reasoning.

Related Interview Questions

  • Determine Whether Courses Can Be Completed - Snapchat (medium)
  • Solve Decimal Coin Change - Snapchat (medium)
  • Find Maximum Island Perimeter - Snapchat (medium)
  • Solve Three Algorithmic Tasks - Snapchat (hard)
  • Implement a Timestamped Counter - Snapchat (medium)
Snapchat logo
Snapchat
Oct 21, 2025, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
3
0
Loading...

Problem

You are given an m x n binary grid grid where:

  • grid[r][c] = 1 represents land
  • grid[r][c] = 0 represents water

An island is a maximal set of land cells connected 4-directionally (up, down, left, right).

The perimeter of an island is the total number of unit edges of land cells that either:

  • lie on the boundary of the grid, or
  • border a water cell.

Return the maximum perimeter among all islands in the grid. If there is no land, return 0.

Input / Output

  • Input: grid: List[List[int]]
  • Output: int (maximum island perimeter)

Constraints (typical interview constraints)

  • 1 <= m, n <= 1000 (or similar)
  • grid[r][c] is 0 or 1
  • Aim for O(mn) time

Example

Given:

grid = [
  [0,1,1,0],
  [0,1,0,0],
  [1,1,0,0]
]

There are two islands; return the larger island’s perimeter.

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Snapchat•More Software Engineer•Snapchat Software Engineer•Snapchat Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.