-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path14.matrix_even_odd
30 lines (30 loc) · 1.03 KB
/
14.matrix_even_odd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
"""
14. MATRIX EVEN ODD
You are required to input the size of the matrix then the elements of matrix,
then you have to divide the main matrix in two sub matrices (even and odd) in such a way that element
at 0 index will be considered as even and element at 1st index will be considered as odd and so on.
Then you have sort the even and odd matrices in ascending order and print the sum of second largest number from both the matrices.
Example
enter the size of array : 5
enter element at 0 index : 3
enter element at 1 index : 4
enter element at 2 index : 1
enter element at 3 index : 7
enter element at 4 index : 9
Sorted even array : 1 3 9
Sorted odd array : 4 7
Sum=7
"""
size=int(input())
arr=list(map(int,input().split(" ")))
even_list=[x for x in arr if arr.index(x)%2==0]
odd_list=[x for x in arr if arr.index(x)%2!=0 ]
even_list=list(set(even_list))
odd_list=list(set(odd_list))
even_list.sort()
odd_list.sort()
print(even_list,odd_list)
if(len(even_list)>=2 and len(odd_list)>=2):
print(even_list[-2]+odd_list[-2])
else:
print(None)