Problem Statement
At the market, there are several buckets of fruit lined up. Feeling a bit mischievious, you notice that they are usually unattended. You want to take as many fruits as possible, without being noticed. However, you suspect that taking the fruit from two adjacent buckets would be too obvious.
You are given int[] fruit indicating the number of fruit in each bucket. Assuming that you will not take fruit from any two adjacent buckets, return the maximum number of fruit you can take.
Definition
- Class:
- BucketThief
- Method:
- maxTake
- Parameters:
- int[]
- Returns:
- int
- Method signature:
- int maxTake(int[] fruit)
- (be sure your method is public)
Constraints
- fruit will contain between 1 and 50 elements, inclusive.
- Each element of fruit will be between 0 and 100, inclusive.
Examples
{ 1, 2, 3 }Returns: 4
There's no sense touching the middle bucket, as that would mean we can't take either of the other two. Best to take the 1 and the 3.{ 18, 5, 2, 13, 2, 9 }Returns: 40
The best we can do here is 18, 13 and 9.{ 1, 1, 10, 10, 1, 1}Returns: 12
There's two buckets with 10 fruit, but we can't take both of them, sadly.{ 28, 65, 32, 7, 99, 14, 32 }Returns: 196