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 Solvers26
Suggested Problems
-
Find the longest sequence of 1's in a binary sequence.
6453 Solvers
-
Project Euler: Problem 5, Smallest multiple
1520 Solvers
-
591 Solvers
-
Matlab Basics - Absolute Value
643 Solvers
-
Sum of the Multiplication of Vectors
276 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!