Skip to the code
cf.
+10 XP

#487 Focus Routes Across a Widget Grid

easy

A dashboard lays out widgets in a grid of rows by cols. Keyboard focus starts on the top-left widget and must reach the bottom-right widget. Each key press moves focus one widget to the right or one widget down.

Write countFocusRoutes(rows, cols) that returns the number of different sequences of key presses that move focus from the top-left widget to the bottom-right widget.

Example 1

Input: rows = 2, cols = 3
Output: 3

Right-right-down, right-down-right, or down-right-right.

Example 2

Input: rows = 3, cols = 3
Output: 6

Any order of 2 rights and 2 downs: there are 6.

Constraints

  • 1 <= rows, cols <= 16
Saved in this browser

Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.

Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).