To get the maximum sum of the twin value of a linklist
twin value means the first should add with last , second should add with second last
eq. 1,2,3,4
then 1+4 and 2+3
This solution done by the list
- get all the element in the list
- get the variable 0 and the length of the list
- sum both the variable
- increase the first one and decrease the last
def pairSum(head):
vec_list = []
while head:
vec_list.append(head.value)
head = head.next
max_sum = 0
len_vec_list = len(vec_list) -1
i = 0
j = len_vec_list
while i<j:
cur_sum = vec_list[i] + vec_list[j]
max_sum = max(max_sum,cur_sum )
i = i+1
j = j-1
return max_sum