PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Snapchat

Count islands with eight-direction adjacency

Last updated: Mar 29, 2026

Quick Overview

This question evaluates a candidate's competency in graph traversal algorithms and data-structure trade-offs by counting connected components on a grid with eight-direction adjacency, focusing on BFS/DFS behavior and optional Union-Find approaches.

  • Medium
  • Snapchat
  • Coding & Algorithms
  • Software Engineer

Count islands with eight-direction adjacency

Company: Snapchat

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: Medium

Interview Round: Technical Screen

You are given an m×n grid of characters '1' (land) and '0' (water). Count the number of islands, where cells are connected if they touch in any of the eight directions (N, NE, E, SE, S, SW, W, NW). Implement an algorithm that returns the island count. Discuss and implement one approach (BFS or DFS), analyze time and space complexity, and explain how you would handle very large grids to avoid recursion limits. Optional: outline a Union-Find solution and compare trade-offs.

Quick Answer: This question evaluates a candidate's competency in graph traversal algorithms and data-structure trade-offs by counting connected components on a grid with eight-direction adjacency, focusing on BFS/DFS behavior and optional Union-Find approaches.

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
Aug 13, 2025, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
1
0

You are given an m×n grid of characters '1' (land) and '0' (water). Count the number of islands, where cells are connected if they touch in any of the eight directions (N, NE, E, SE, S, SW, W, NW). Implement an algorithm that returns the island count. Discuss and implement one approach (BFS or DFS), analyze time and space complexity, and explain how you would handle very large grids to avoid recursion limits. Optional: outline a Union-Find solution and compare trade-offs.

Submit Your Answer

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 8,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.