You are given an array of numbers, and you are asked to minimize the total "" incurred when reducing the array to a single number. To achieve this, you need to follow these steps:
Choose one of the two numbers you selected in the previous step and remove it from the array. Concatenate the remaining numbers.
Repeat the above two steps until the array is reduced to a single number.
The " " is defined as the bitwise of all the costs incurred in reducing the array to a single number.
Input Format :
An integer denoting the size of the array
integers denoting the elements of the array
Output Format :
Print one integer, the minimum
Constraints :
Sure, here's a possible rephrased version of the explanation:
Consider the following example array: [1, 5, 2, 3]. To minimize the total "OR cost," we can follow these steps:
Select 1 and 5. Remove 5 from the array, and concatenate the remaining numbers [1, 2, 3]. The cost incurred is
Select 1 and 2. Remove 2 from the array, and concatenate the remaining numbers [1, 3]. The cost incurred is
Select 1 and 3. Remove 1 from the array, and concatenate the remaining numbers [3]. The cost incurred is
Thus, the total "OR cost" is the bitwise OR of the individual costs incurred, which is = 14. It can be shown that we can never achieve a total cost less than 14 for this particular array.