House Robber Problem C easy to understand Sol

My first basic sol where no confusion needed and just easy to understand :)
condition is: adjacent houses cannot be robbed
Solution: So s0 can be first house, s1 can be second house,

  • s2 to (first+3rd) houses
  • In a loop starting from 4th house, (where this 4th house can be added to s0 and s1 as not adjacent)
  • Keep adding the current element to s0 and current element to s1
    compare the sums and assign to s,
  • Keep assigning the max value from s
  • Keep moving s0 to s1, s1 to s2, s2 to s..

Next optimized solution, where tried to some temp variables, additions.. :

--

--

www.linkedin.com/in/jyothivs

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store