Company: Wipro-Project engineer-on campus_23may
Difficulty: medium
You are given an array A of N integers. Call three elements of A non-adjacent when every pair of their indices differs by more than 1. What is the largest possible sum you can get from three such non-adjacent elements of A? For example, given A = [8, -4, -7, -5, -5, -4, 8, 8]: elements in positions 0, 3 and 6 are non-adjacent and their sum is 8 + (-5) + 8 = 11; elements in positions 0, 6, 7 sum up to 8 + 8 + 8 = 24, but are not non-adjacent; elements in positions 0, 5, 7 are non-adjacent and sum up to 8 + (-4) + 8 = 12. The third option turns out to be the best, since no other choice of three non-adjacent elements can beat that sum. Write a function: def solution(A) that, given an array A of N integers, returns the maximum sum of three non-adjacent elements from A. Examples: Given A = [8, -4, -7, -5, -5, -4, 8, 8], the function should return 12. As explained above, you can choose elements in positions 0, 5 and 7. Given A = [-2, -8, 1, 5, -8, 4, 7, 6], the function should return 15. The