1818 Views

0 Likes

In this lesson, Alvin explores the strategy to solving the following interview problem:

Write a function,

island_count, that takes in a grid containing Ws and Ls. W represents water and L represents land. The function should return the number of islands on the grid. An island is a vertically or horizontally connected region of land.

```
grid = [
['W', 'L', 'W', 'W', 'W'],
['W', 'L', 'W', 'W', 'W'],
['W', 'W', 'W', 'L', 'W'],
['W', 'W', 'L', 'L', 'W'],
['L', 'W', 'W', 'L', 'L'],
['L', 'L', 'W', 'W', 'W'],
]
island_count(grid) # -> 3
```

```
grid = [
['L', 'W', 'W', 'L', 'W'],
['L', 'W', 'W', 'L', 'L'],
['W', 'L', 'W', 'L', 'W'],
['W', 'W', 'W', 'W', 'W'],
['W', 'W', 'L', 'L', 'L'],
]
island_count(grid) # -> 4
```

```
grid = [
['L', 'L', 'L'],
['L', 'L', 'L'],
['L', 'L', 'L'],
]
island_count(grid) # -> 1
```

If you need additional support taking these DSA skills and actually applying them, take **Alvin's** *complete* data structures and algorithms course on **Structy**. You can try out the concepts yourself in their interactive code editor and learn advanced DSA patterns like stack exhaustive recursion.

Use **this link to get 20% off** the entire Structy DSA learning experience.

Follow Alvin on LinkedIn: **https://www.linkedin.com/in/alvin-zablan-b73a92117/**

Related Videos

0:48

DSA Crash Course [Part 87] - Outro

5:27

DSA Crash Course [Part 86] - Array Stepper Walkthrough

5:39

DSA Crash Course [Part 85] - Array Stepper Approach

6:31

DSA Crash Course [Part 84] - Counting Change Walkthrough

6:26

DSA Crash Course [Part 83] - Counting Change Approach

5:52

DSA Crash Course [Part 82] - Summing Squares Walkthrough

6:22

DSA Crash Course [Part 81] - Summing Squares Approach

8:00

DSA Crash Course [Part 80] - Non Adjacent Sum Walkthrough

8:33

DSA Crash Course [Part 79] - Non Adjacent Sum Approach

5:34

DSA Crash Course [Part 78] - Max Path Sum Walkthrough

Explore TrendingLayoffsPerformance Improvement PlanSystem DesignInterpersonal CommunicationTech Lead