Jump Game III LeetCode solution in JavaScript
1// Recursion, Backtracking2var canReach = function (arr, start) {3if (arr === null || arr.length === 0) {4return false;5}6return dfs(arr, start);7// T.C: O(N)8// S.C: O(N)9};1011const dfs = (arr, idx) => {12if (arr[idx] === 0) {13return true;14}15if (idx < 0 || idx > arr.length - 1 || arr[idx] < 0) {16return false;17}18let jump = arr[idx];19arr[idx] = -1; // marking this index as visited20return dfs(arr, idx - jump) || dfs(arr, idx + jump);21};