java.lang.Object
g1201_1300.s1269_number_of_ways_to_stay_in_the_same_place_after_some_steps.Solution

public class Solution extends Object
1269 - Number of Ways to Stay in the Same Place After Some Steps.<p>Hard</p> <p>You have a pointer at index <code>0</code> in an array of size <code>arrLen</code>. At each step, you can move 1 position to the left, 1 position to the right in the array, or stay in the same place (The pointer should not be placed outside the array at any time).</p> <p>Given two integers <code>steps</code> and <code>arrLen</code>, return the number of ways such that your pointer still at index <code>0</code> after <strong>exactly</strong> <code>steps</code> steps. Since the answer may be too large, return it <strong>modulo</strong> <code>10<sup>9</sup> + 7</code>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> steps = 3, arrLen = 2</p> <p><strong>Output:</strong> 4</p> <p><strong>Explanation:</strong> There are 4 differents ways to stay at index 0 after 3 steps.</p> <p>Right, Left, Stay</p> <p>Stay, Right, Left</p> <p>Right, Stay, Left</p> <p>Stay, Stay, Stay</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> steps = 2, arrLen = 4</p> <p><strong>Output:</strong> 2</p> <p><strong>Explanation:</strong> There are 2 differents ways to stay at index 0 after 2 steps</p> <p>Right, Left</p> <p>Stay, Stay</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> steps = 4, arrLen = 2</p> <p><strong>Output:</strong> 8</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= steps <= 500</code></li> <li><code>1 <= arrLen <= 10<sup>6</sup></code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • numWays

      public int numWays(int steps, int arrLen)