Question
You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping
You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent houses have security systems connected and it will automatically contact the police if two adjacent houses were broken into on the same night. Given an integer array M representing the amount of money of each house, return the maximum amount of money you can rob tonight without alerting the police. You don't need to write real C++ codes, but you are welcome to do so. Pseudocodes are necessary.
Example 1: M = {1, 2, 3, 1}.
Output: 4.
Explanation: House 1 and 3, in total 4, which is the largest. House 2 and 4, in total 3.
Example 2: M = {2, 7, 9, 3, 1}.
Output: 12.
Explanation: House 1, 3, 5, in total 12, which is the largest. House 2, 4, 6, in total 11.
a)Use brute-force method to solve this problem. Design an algorithm and analyze the time and space complexity.
b)Optimize the brute-force solution. Design a new algorithm and analyze the time and space complexity.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started