Distinct Islands Problem Statement

Given a two-dimensional array/list consisting of integers 0s and 1s, where 1 represents land and 0 represents water, determine the number of distinct islands. A group of connected 1s (horizontally or vertically) forms an island.

Note:

Two islands are considered the same if one can be translated to overlap the other without rotation or reflection. If this condition is satisfied, they are considered identical.

Example:

Input:
 1 1 0
0 0 1
0 0 1
Output:
2
Explanation:

Here, two islands exist and they cannot be translated to overlap each other, thus they are distinct.

Example:

Input:
 1 1 0 0 0
1 1 0 0 0
0 0 0 1 1
0 0 0 1 1
Output:
1
Explanation:

These islands can be translated to overlap each other, thus they are not distinct. Only one distinct island exists.

Input:

N, M

The first two numbers are the dimensions of the array: 'N' rows and 'M' columns.

The subsequent 'N' lines provide the values for each row, with each row containing 'M' space-separated values of the array.

Output:

Total number of distinct islands.

Constraints:

  • 0 ≤ N ≤ 1000
  • 0 ≤ M ≤ 1000
  • Array elements are either 0 or 1
  • Time Limit: 1 sec
AnswerBot
4mo

Count the number of distinct islands in a 2D array of 0s and 1s.

  • Identify connected groups of 1s to form islands

  • Check if islands can be translated to overlap without rotation or reflection

  • Count the num...read more

Help your peers!
Select
Add answer anonymously...

Expedia Group Software Developer Intern interview questions & answers

A Software Developer Intern was asked Q. Minimum Distinct Labels Problem Statement You are given N boxes on a table, each...read more
A Software Developer Intern was asked Q. Encode the Message Problem Statement Given a text message, your task is to retur...read more
A Software Developer Intern was asked Q. Incremental Partitioning Problem Statement Given two integers N and K, determine...read more

Popular interview questions of Software Developer Intern

A Software Developer Intern was asked Q1. Minimum Distinct Labels Problem Statement You are given N boxes on a table, each...read more
A Software Developer Intern was asked Q2. Encode the Message Problem Statement Given a text message, your task is to retur...read more
A Software Developer Intern was asked Q3. Incremental Partitioning Problem Statement Given two integers N and K, determine...read more
Expedia Group Software Developer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits