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.
Replace NaNs with the number that appears to its left in the row.
How to find the position of an element in a vector without using the find function
Is my wife right?
Next Higher Power of B
Given a square and a circle, please decide whether the square covers more area.
Zigzag of square matrix
determine the sum of fraction part for given matrix
Find the treasures in MATLAB Central and discover how the community can help you!
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Contact your local office