Can someone tell me how to solve this question that was asked in TCS CODEVITA ?
Pascal’s triangle giving binomial coefficients is well known. In this triangle, elements in each row can be obtained by adding two adjacent elements in the previous row. The pyramid of numbers we construct in this problem is similar to the Pascal triangle. We start with six numbers at the base of the pyramid, and construct the pyramid one layer at a time by adding the two adjacent numbers in the previous layer. For Example, starting with the numbers 1 2 3 4 5 6 in the base, we get the following pyramid.
The apex of the pyramid is filled with the product of the numbers in the row below instead of the sum.
In the above pyramid, the apex is filled with the number 48 x 64 =3072. The aim is to get the largest number possible at the apex of the pyramid.
The input will be a set of N positive integers. Six need to be chosen from these and arranged at the base to get the largest possible number at the top.
The first line of the input is N, the total number of integers that will be given.
The second line is a set of N (not necessarily distinct) comma separated positive integers from which the six numbers at the base need to be selected.
The output is one line with an integer representing the maximum value of the apex of the pyramid when six integers are selected and arranged suitably at the base.
N < 13
Integers provided for selection ≤ 100
There are 8 numbers given, from which the 6 numbers in the base are to be selected and arranged so as to maximize the apex number. One way of doing this is in the figure below.
The product of the two numbers below the apex is 746415, which is the output.