Ways to Reach After K Steps

On an infinite number line, count distinct sequences of ±1 moves that reach a target position in exactly k steps. The answer is C(k, (k + d)/2) where d is the distance, if (k-d) is non-negative and even.

Examples
Input: [0,2,4]
Output: 4
Hints

Ways to Reach After K Steps

On an infinite number line, count distinct sequences of ±1 moves that reach a target position in exactly k steps. The answer is C(k, (k + d)/2) where d is the distance, if (k-d) is non-negative and even.