Interview Query

NxN Grid Traversal

Start Timer

0:00:00

Upvote
4
Downvote
Save question
Mark as completed
View comments (8)
Next question

Given an integer nn, write a function traverse_count to determine the number of paths from the top left corner of an n×nn\times n grid to the bottom right. You may only move right or down.

Example:

Input:

n = 2

Output:

def traverse_count(n) -> 2

As our two options for a 2x2 grid:

start
end

are only to go right then down, or down then right. So there are two possible paths.

.
.
.
.
.


Comments

Loading comments