Skip to content

Instantly share code, notes, and snippets.

@spiterman
Last active March 28, 2019 00:16
Show Gist options
  • Select an option

  • Save spiterman/4cf87c821dfef8fe8589c0f6433eafea to your computer and use it in GitHub Desktop.

Select an option

Save spiterman/4cf87c821dfef8fe8589c0f6433eafea to your computer and use it in GitHub Desktop.
function houseRobberRecursive(arr) {
function stealFromHouse(index) {
if(index >= arr.length) {
return 0;
}
return Math.max(arr[index] + stealFromHouse(index + 2), stealFromHouse(index + 1));
}
return stealFromHouse(0);
}
// console.log(houseRobberRecursive([3, 1, 2, 5, 4, 2])) // => 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment