Exiger Interview 1st Round Question

You are in an apple orchard with magic apple trees. You can harvest the apples from a tree simply by pointing at it (selecting that value from the array). However, harvesting the apples from a tree causes the adjacent trees to wilt and lose all their fruit (number can no longer be selected from the array). What is the highest number of apples that you can obtain?

Example 1: trees = new int[]{10, 2, 3, 100, 4};
Output: 110
Explanation: Choosing trees[0] and trees[3] harvest 110 apples, and wilts the adjacent trees, excluding them from the total

Example 2: [2, 7, 9, 3, 1]
Output: 12
Explanation: trees[0] + trees[2] + trees[4] = 12

1 hour given

Comments (3)