Mid From PDF Coding C# Coding Interview

House Robber?

int HouseRobber(int[] nums) {
if (nums.Length == 0) return 0;
if (nums.Length == 1) return nums[0];
int prev1 = 0, prev2 = 0;
foreach (var num in nums) {
int temp = prev1;
prev1 = Math.Max(prev2 + num, prev1);
prev2 = temp;
}
return prev1;
}

More from C# Programming Tutorial

All questions for this course
Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details