Input: arr[] = { 2, 4, 16 }
Output: 9
Explanation:
Inserting (arr[2] – arr[1]) modifies arr[] to { 2, 4, 12, 16 }
Inserting (arr[2] – arr[1]) modifies arr[] to { 2, 4, 8, 12, 16 }
Inserting (arr[2] – arr[1]) modifies arr[] to { 2, 4, 6, 8, 12, 16 }
Inserting (arr[4] – arr[0]) modifies arr[] to { 2, 4, 6, 8, 10, 12, 16 }
Inserting (arr[6] – arr[0]) modifies arr[] to { 2, 4, 6, 8, 10, 12, 14 16 }
Inserting (arr[2] – arr[0]) modifies arr[] to { 2, 4, 4 6, 8, 10, 12, 14 16 }
Inserting (arr[2] – arr[1]) modifies arr[] to { 0, 2, 4, 4 6, 8, 10, 12, 14 16 }
Therefore, the required output is 9.
Input: arr[] = { 3, 6, 5, 4 }
Output: 7