Profile picture
Alvin ZablanFounder at Structy and React Formula | ex-Google

Count Paths Approach

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

Write a function, count_paths, that takes in a grid as an argument. In the grid, 'X' represents walls and 'O' represents open spaces. You may only move down or to the right and cannot pass through walls. The function should return the number of ways possible to travel from the top-left corner of the grid to the bottom-right corner.

grid = [
["O", "O"],
["O", "O"],
]

count_paths(grid) # -> 2
grid = [
["O", "O", "X"],
["O", "O", "O"],
["O", "O", "O"],
]

count_paths(grid) # -> 5
grid = [
["O", "O", "O"],
["O", "O", "X"],
["O", "O", "O"],
]

count_paths(grid) # -> 3

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/