Problem 44649. Minimum Maximum Sort Array
Solution Stats
Problem Comments
-
7 Comments
Please generalise your Test Suite, as otherwise trivial submissions like Solution 1536595
will pass. See Problem 44616 for additional discussion. —DIV
Added some test cases to make the problem generalised. Might not be exactly according to what OP meant the problem to be.
Dyuman, I might be misunderstanding this problem, but I think Test 5 is incorrect since exp(1) > sin(exp(1)).
Chris, what is your understanding of the problem (from the problem statement given by OP and correspondingly the test suite)?
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 Solvers23
Suggested Problems
-
9927 Solvers
-
Who knows the last digit of pi?
656 Solvers
-
13885 Solvers
-
158 Solvers
-
181 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!