How to Find Number of Distinct Islands?
By: House Of Codes
Tags: Software Development, Coding, Interview, Computer Science, Java

How to Find Number of Distinct Islands?

Day 50— 100 Days to LinkedIn, Yahoo, Oracle

Photo by Marek Okon on Unsplash

Out of Free Stories? Here is my Friend Link.

100 Days to LinkedIn, Yahoo, Oracle

Introduction

Hey guys, Today is day 50 of the 100 Days to LinkedIn Challenge.

Free For Kindle Readers

If you are Preparing for your Interview. Even if you are settled down in your job, keeping yourself up-to-date with the latest Interview Problems is essential for your career growth. Start your prep from Here!

Last month, I have been researching to find out the Frequently asked problems from these Companies. I have compiled 100 of these questions, I am not promising you that you will get these questions in your interview but I am confident that most of these “interview questions” have similar logic and employs the same way of thinking from these set of challenges.

Before we move on to the first problem, If you are wondering why I chose LinkedIn, Yahoo and Oracle over FAANG are because I have completed a challenge Focusing on Amazon and Facebook Interview.

New Day, New Strength, New Thoughts

Day 50 — Number of Distinct Islands🏁

AIM

Given a non-empty 2D array grid of 0's and 1's, an island is a group of 1 's (representing land) connected 4-directionally (horizontal or vertical.) You may assume all four edges of the grid are surrounded by water.

Count the number of distinct islands. An island is considered to be the same as another if and only if one island can be translated (and not rotated or reflected) to equal the other.

Example🕶

11000

11000

00011

00011

Follow House of Codes for keeping up to date in the programming interview world.

Code👇

Algorithm

If you know the direction of an island, then the mirror will be the same permutation. Create a Set, to store the direction of the Islands. Traverse the grid, at each index check whether the cell is 1 which indicates a part of the island. For Each 1, Traverse in a Depth First Search so that you can store the direction in the Set. At the end of the traversal, return the Set of Islands🔚

Complexity Analysis

Time Complexity : O(R * C); R- No of Rows, C- No of Columns

Space Complexity : O(N) Number of Islands present in the Grid

Thanks for Making this #1 New Release 🖤

Further Reading

4 Incredibly Useful Linked List Tips for Interview

Top 25 Amazon SDE Interview Questions

Do you think you really know about Fibonacci Numbers?

9 Best String Problems Solved using C Programming

One Does not Simply Solve 50 Hacker Rank Challenges

End of the Line

You have now reached the end of this article. Thank you for reading it. Good luck with your Programming Interview!

If you come across any of these questions in your interview. Kindly Share it on the comments section below. I will be thrilled to read them.

Don’t forget to hit the follow button✅to receive updates when we post new coding challenges. Tell us how you solved this problem. 🔥 We would be thrilled to read them. ❤ We can feature your method in one of the blog posts.

Want to become outstanding in java programming?

A compilation of 100 Java(Interview) Programming problems which have been solved. (Hacker Rank) 🐱‍💻. This is completely free 🆓 if you have an amazon kindle subscription.