Intro: As far as I could search, this question wasn\'t asked in SO yet.
This is an interview question.
I am not even specifically looking for a code sol
I think this should work:
Find the minimum 3 element and their indices. Since all of them can't be adjacent choose 2 among them.
If all of them are adjacent and the minimum number is in the middle of them, iterate through all elements, find the forth minimum element, choose minimum of min1+min4
, min2+min3
, whichever is smaller.
You can do this in one iteration too.