Largest Pair Of Smallest Elements

easy
1. You are given an array of integers.
  2. You have to find the sum of smallest and second smallest elements for all the subarrays(of size>=2),
     and then return the maximum sum among them.
  
  Example : 4 5 2 7
  For[4,5] -> sum=9, For[4,5,2] -> sum=6, For[4,5,2,7] -> sum=6,
  For[5,2] -> sum=7, For[5,2,7] -> sum=7,For[2,7] -> sum=9  
  Answer : 9

Input Format

First line contains size of the given array 'N' Second line contains N number of integer values for array

Output Format

return an integer

Constraints

2<=N<=10^3
  1<=A[i]<=10^18

Notice

Try First, Check Solution later

1. You should first read the question and watch the question video.
2. Think of a solution approach, then try and submit the question on editor tab.
3. We strongly advise you to watch the solution video for prescribed approach.

Example

Input
5
4 3 1 5 6
Output
11
Previous
Decoding A String
Next
Finding Smaller Towards Left And Right

Related Questions