Problem 44649. Minimum Maximum Sort Array
Solution Stats
Problem Comments
-
7 Comments
Dyuman, I thought the problem asked us to (1) sort the vector, (2) move the max value to the second position, and (3) append a flipped version of the result of step 2 to the end. So for the example given:
1. Sort: [1 2 3 5]
2. Move the max value: [1 5 2 3]
3. Flip and append: [1 5 2 3 3 2 5 1]
For test 5, this approach gives [sin(pi) pi sin(exp(1)) exp(1) exp(1) sin(exp(1)) pi sin(pi)].
I suppose one could interpret the original statement as sort the vector ascending and descending and interleave the values, min first. That gives the same answer for test 5 (but not a test with >4 values).
The way I have added the test cases is that - min max and then the rest of the array as it is and it's flipped result appended to it. Hope this helps.
I understand your approach, but this is what I used to generalise the problem.
OK, thanks!
Solution Comments
Show commentsProblem Recent Solvers25
Suggested Problems
-
3447 Solvers
-
Back to basics 8 - Matrix Diagonals
936 Solvers
-
Flip the main diagonal of a matrix
844 Solvers
-
Arrange vector in ascending order
788 Solvers
-
Is this triangle right-angled?
6092 Solvers
More from this Author2
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!