FastPrepNumber of Ways to Reach a Position After Exactly K Steps

Number of Ways to Reach a Position After Exactly K Steps

Bloomberg LP logoBloomberg LP● MediumNEW GRADPHONE SCREEN

Updated

Problem statement

You stand at integer position startPos. Each step moves exactly one unit left or right.

Return the number of distinct step sequences that reach endPos after exactly k steps, modulo 1,000,000,007.

Function

numberOfWays(startPos: int, endPos: int, k: int) → int

Examples

Example 1

startPos = 1endPos = 2k = 3return = 3

Exactly two right moves and one left move are needed, which can be ordered in three ways.

Example 2

startPos = 2endPos = 5k = 10return = 0

The distance and step count have different parity.

Constraints

  • -1000 <= startPos, endPos <= 1000.
  • 0 <= k <= 1000.

More Bloomberg LP Phone Screen questions

Similar questions at other companies

Bloomberg LP interview experiences

All Bloomberg LP interview questionsSee Bloomberg LP hiring insights
Saved
class Solution {
    public int numberOfWays(int startPos, int endPos, int k) {
        // Write your code here.
    }

}
Checking account…