Tap here to switch tabs
Problem
Submissions

Problem: Number of Ways to Reach Destination in the Grid

med
30 min
Try to solve the Number of Ways to Reach Destination in the Grid problem.

Statement

You are given two integers n and m representing the dimensions of a 11 indexed nimesmn imes m grid. You are also given an integer k and two arrays source and dest, each of length 22, where source is the starting cell and dest is the destination cell.

At each step, you can move from the current cell to any other cell that is located in the same row or the same column as the current cell.

Return the total number of distinct paths to reach dest from source in exactly k steps. Since the answer may be large, return it modulo 109+710^9 + 7.

Constraints:

  • 2≤2 \leq n, m ≤109\leq 10^9

  • 1≤1 \leq k ≤105\leq 10^5

  • source.length ==== dest.length ==2== 2

  • 1≤1 \leq source[0], dest[0] ≤\leq n

  • 1≤1 \leq source[1], dest[1] ≤\leq m

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Number of Ways to Reach Destination in the Grid

med
30 min
Try to solve the Number of Ways to Reach Destination in the Grid problem.

Statement

You are given two integers n and m representing the dimensions of a 11 indexed nimesmn imes m grid. You are also given an integer k and two arrays source and dest, each of length 22, where source is the starting cell and dest is the destination cell.

At each step, you can move from the current cell to any other cell that is located in the same row or the same column as the current cell.

Return the total number of distinct paths to reach dest from source in exactly k steps. Since the answer may be large, return it modulo 109+710^9 + 7.

Constraints:

  • 2≤2 \leq n, m ≤109\leq 10^9

  • 1≤1 \leq k ≤105\leq 10^5

  • source.length ==== dest.length ==2== 2

  • 1≤1 \leq source[0], dest[0] ≤\leq n

  • 1≤1 \leq source[1], dest[1] ≤\leq m