- Complete one codeFight per day
- Apply to 10 jobs outside of Hired.com
- Complete at least one interview from Hired.com
- Write a blog on Webpack for Sweetcode.io
Last active
May 23, 2017 17:55
-
-
Save pllearns/10791adb081a0e7e3b39f6e049b5989a to your computer and use it in GitHub Desktop.
Week 49 - Get Hired Goal
This file contains 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
// First code fight solution - from a problem asked at LinkedIn | |
function houseRobber(nums) { | |
// determine what has been robbed and what hasn't | |
var robbed = 0 | |
var notRobbed = 0 | |
// go through the houses | |
for (var i = 0; i < nums.length; i++) { | |
// add the current houseRobbed to what hasn't been robbed | |
var currentRobbery = notRobbed + nums[i] | |
// determine where I'm haven't robbed | |
var currentNotRobbed = Math.max(notRobbed, robbed) | |
// where I didn't rob, so I won't get money here | |
notRobbed = currentNotRobbed | |
// where I did rob | |
robbed = currentRobbery | |
} | |
// returning the sum of what I can and did rob | |
return Math.max(robbed, notRobbed) | |
} | |
console.log(houseRobber([2,3,4])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment