There are several trees arranged in a circle, each with a fruit value associated with it. A bird can gather all the fruits from a tree by sitting on it for 0.5 seconds and can move to a neighboring tree in another 0.5 seconds. Once all the fruits are picked from a tree, the bird cannot pick any more from that tree until all fruits are picked, it cannot move to next tree. The bird has totalTime seconds to gather as many fruits as possible and can start from any tree.
Given the array arr[] of fruit values and totalTime, determine the maximum number of fruits the bird can gather.
Example 1
Input: arr[] = [2, 1, 3, 5, 0, 1, 4], totalTime = 3
Output: 9
Explanation: Starting at tree 1 and moving to tree 2, then to tree 3, the bird gathers 1 + 3 + 5 = 9 fruits.
Example 2
Input: arr[] = [1, 6, 2, 5, 3, 4], totalTime = 2
Output: 8
Explanation: Starting at tree 1 and moving to tree 2, the bird gathers 6 + 2 = 8 fruits. Alternatively, starting at tree 3 and moving to tree 4, the bird also gathers 5 + 3 = 8 fruits.
Sign in to write, run, and submit your solution against the full test suite.