Last active
March 28, 2019 00:16
-
-
Save spiterman/4cf87c821dfef8fe8589c0f6433eafea to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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