Join Regular Classroom : Visit ClassroomTech

Revature Question Solve | Sum of Multiplication and Division | Codewindow.in

Write a program to get the Sum of multiplication and division of the 2nd largest element with the
smallest element of an arrray.

Input Format
First line contains an integer, denotes the size of the array
Second line contains the elements of an array.

Sample Input:
5
1 3 4 8 13
Sample Output:
16

Explanation
Here in this array, 8 is the largest number and 1 is the smallest number. So, when we multiply
and divide 8 with 1 respectively we get 8 in both the cases. and then we sum up 8 with 8 it will
result in 16.

Solution:
Python 3.7:

#solution by codewindow.in
x=int(input())
n=list(map(int, input().split()))
n.sort()

#print(n)
#print(n[0]*n[-2])
#print(n[-2]//n[0])

res = (n[0]*n[-2]) + (n[-2]//n[0])
print(res)

Also Checkout

Recent Posts
Pages