Company: LG ads
Difficulty: medium
1. Trick or treat Jack is going trick-or-treating on Halloween in his neighborhood. There are n houses in a line, each offering a different number of candies. However, Jack cannot visit two adjacent houses for treats. Given an array of size n , where each index represents the number of candies he can get from that house, find the maximum number of candies that Jack can collect this Halloween. Function Description Complete the function trickOrTreat in the editor below. Function Parameters: int candies[n] : number of candies from Jack can get from each house. Returns int : the maximum number of candies Jack can get. Constraints 1 ≤ candies.length ≤ 100000 0 ≤ candies[i] ≤ 400 Input Format Input from stdin will be processed as follows and passed to the function: The first line contains an integer n, the size of the array candies. Each of the next n lines contains an integer candies[i]. Examples Sample Case 0 Input: candies = [6, 7, 1, 3, 8, 2, 4] Output: 19 Jack will take from house 1, 3,