Be careful! You don't have to find the max element in the range . You have to find maximum subvector sum in the range . i . e if array is {1,2,-4,1}......answer should be 3 because 1+2>than all combinations added together linearly .