Question
Function: swapNext2BigNext2Small Input: 1. (1×N double) A Vector of numbers (N>=4) Output: 1. ( 1xN double) A Vector Function Description: - Given a 1XN vector where N>=4, return a new vector with the next to largest and next to smallest values swapped Note(s): - All values that are not being swapped should stay in the same location. - There will be no duplicate values in the vector Hint(s): - sort() may be useful - Use of a variable to hold a value may be helpful Examples:
lokaranjan1452
lokaranjan1452
Answers
There are no human answers yet.
Answered by
GPT 3.5
Example 1:
Input: [3, 7, 2, 6, 1, 9]
Output: [3, 1, 2, 6, 7, 9]
Explanation:
In the input vector, the next to largest value is 7 and the next to smallest value is 2. Swapping these two values will result in the output vector.
Example 2:
Input: [5, 9, 12, 4, 8, 1, 6]
Output: [5, 1, 12, 4, 8, 9, 6]
Explanation:
In the input vector, the next to largest value is 9 and the next to smallest value is 4. Swapping these two values will result in the output vector.
Example 3:
Input: [1, 2, 3, 4, 5, 6, 7, 8]
Output: [1, 7, 3, 4, 5, 6, 2, 8]
Explanation:
In the input vector, the next to largest value is 7 and the next to smallest value is 2. Swapping these two values will result in the output vector.
Example 4:
Input: [10, 15, 20, 25, 30, 35, 40]
Output: [10, 35, 20, 25, 30, 15, 40]
Explanation:
In the input vector, the next to largest value is 35 and the next to smallest value is 15. Swapping these two values will result in the output vector.
Input: [3, 7, 2, 6, 1, 9]
Output: [3, 1, 2, 6, 7, 9]
Explanation:
In the input vector, the next to largest value is 7 and the next to smallest value is 2. Swapping these two values will result in the output vector.
Example 2:
Input: [5, 9, 12, 4, 8, 1, 6]
Output: [5, 1, 12, 4, 8, 9, 6]
Explanation:
In the input vector, the next to largest value is 9 and the next to smallest value is 4. Swapping these two values will result in the output vector.
Example 3:
Input: [1, 2, 3, 4, 5, 6, 7, 8]
Output: [1, 7, 3, 4, 5, 6, 2, 8]
Explanation:
In the input vector, the next to largest value is 7 and the next to smallest value is 2. Swapping these two values will result in the output vector.
Example 4:
Input: [10, 15, 20, 25, 30, 35, 40]
Output: [10, 35, 20, 25, 30, 15, 40]
Explanation:
In the input vector, the next to largest value is 35 and the next to smallest value is 15. Swapping these two values will result in the output vector.
Submit Your Answer
We prioritize human answers over AI answers.
If you are human, and you can answer this question, please submit your answer.