3
HashMap<String, Long> map = new HashMap();5
public int numWays(int steps, int arrLen) {7
return (int) (ways(steps, arrLen, 0) % ((Math.pow(10, 9)) + 7));10
public long ways(int steps, int arrLen, int index) {11
String curr = index + "->" + steps;13
if (index == 0 && steps == 0) {15
} else if (index < 0 || (index >= arrLen) || steps == 0) {19
if (map.containsKey(curr)) {22
long stay = ways(steps - 1, arrLen, index);23
long right = ways(steps - 1, arrLen, index + 1);24
long left = ways(steps - 1, arrLen, index - 1);26
map.put(curr, (stay + right + left) % 1000000007);28
return (right + left + stay) % 1000000007;