Skip to content

Practice Number of Ways to Stay in the Same Place After Some Steps

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Hard#1269
LeetCode Problem

Number of Ways to Stay in the Same Place After Some Steps

Problem Statement

You have a pointer at index 0 in an array of size arrLen. 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). Given two integers steps and arrLen, return the number of ways such that your pointer is still at index 0 after exactly steps steps. Since the answer may be too large, return it modulo 10^9 + 7.

Source: Number of Ways to Stay in the Same Place After Some Steps on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
steps = 3, arrLen = 2
Output
4

# Example 2

Input
steps = 2, arrLen = 4
Output
2

# Example 3

Input
steps = 4, arrLen = 2
Output
8

Constraints

1 <= steps <= 500
1 <= arrLen <= 10^6

Related LeetCode Problems

Practice more problems similar to Number of Ways to Stay in the Same Place After Some Steps.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.