Author | Message |
---|---|
AndersonChristoph
Posts: 34
|
Posted 00:08 Jan 17, 2015 |
I'm not quite sure I understand this: "Replace each element except the first and last by the larger of its two neighbors." If I have the array: 4 16 15 6 8 Do I return: 4 16 16 16 8? |
Adam Berman
Posts: 19
|
Posted 09:23 Jan 17, 2015 |
I think the output he wants is 4 15 16 15 8, but I'm not really sure. Last edited by Adam Berman at
09:23 Jan 17, 2015.
|
kknaur
Posts: 540
|
Posted 14:50 Jan 17, 2015 |
Adam is correct. You should check the neighbors in the original array and NOT the resulting array whose values you are filling in. Also some students have asked if the current position you are looking at should be considered as a max and the answer is no. Only consider the larger of the two neighbors to the left and right of the index you are currently on. |