Question: USE C++ ONLY You are given a ladder array of n integers. You need to sort it using a Deque. You can use built-in Deque

USE C++ ONLY

You are given a ladder array of n integers. You need to sort it using a Deque. You can use built-in Deque for this problem. The expected Time Complexity is O(n).

A ladder array is an array that is increasing at first, then decreases after that.

For example: [1,3,5,7,2,0] is a ladder array because 1 < 3 < 5 < 7 > 2 > 0. It is increasing till value 7, then it is decreasing after that.

Input

Output

6

1 3 5 7 2 0

0 1 2 3 5 7

5

4 6 2 1 0

0 1 2 4 6

Hint: You just need to compare the values at the front and back of the Deque.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!