Use the solution from House Robber and run it on the arrays excluding h0 and hn
classSolution:defrob(self, nums: List[int])->int:# nums = [1,2,2,3,5,1]# if you are i = 0, you cannot rob house n - 1iflen(nums)==1:return nums[0]defhouse_robber(nums): n =len(nums) opt =[0]* n
opt[n -1]= nums[n -1] opt[n -2]= nums[n -2]for i inrange(n -3,-1,-1): opt[i]= nums[i]+max(opt[i +2: n])returnmax(opt)returnmax(nums[0], house_robber(nums[1:]), house_robber(nums[:-1]))