Skip to content

Instantly share code, notes, and snippets.

@pllearns
Last active May 23, 2017 17:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pllearns/10791adb081a0e7e3b39f6e049b5989a to your computer and use it in GitHub Desktop.
Save pllearns/10791adb081a0e7e3b39f6e049b5989a to your computer and use it in GitHub Desktop.
Week 49 - Get Hired Goal
// 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]))

Get Hired Specs - Week 49

  • 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment