Prize Collection II
ARRAY
DYNAMIC PROGRAMMING
Problem
In a circular contest setup, booths are arranged such that the first and last booths are neighbors. Each booth offers a prize, but collecting from two consecutive booths triggers a penalty.
Given an array of integers booths
that indicates the reward at each booth, calculate the maximum reward you can gather without visiting two adjacent booths in a row.
Examples
collect([5, 1, 2, 6]) // return 7 // Why? Max collection is 5 + 2 = 7 collect([4, 1, 2, 7, 5, 3, 1]) // return 14 // Why? Max collection is 4 + 7 + 3 = 14
Loading...
Loading...Loading...