FastPrepFastPrep
Problem Brief

Arrange Flower Sticks

OA

Emma wishes to give her father a bouquet for his birthday. She asks for help from her mother Rosy. Rosy gives N flower sticks numbered 1 to N to Emma and tells her to arrange them in the bouquet in a particular order. She asks Emma to arrange the first K flower sticks in the order of increasing length and the remaining sticks in the order of decreasing length.

Write an algorithm to find the final arrangement of the flower sticks in the bouquet.

Input

The first line of the input consists of an integer - flowerStick_size, representing the number of flower sticks (N).

The second line consists of N space-separated integers- flowerStick[1], flowerStick[2],...,flowerStick[N], representing the length of the flower sticks.

The last line consists of an integer - random, representing the number K given by Rosy to Emma.

Output

Print N space-separated integers representing the final arrangement of the flower sticks in the bouquet.

Constraints

0 ≤ random ≤flowerStick_size
0 < flowerStick_size < 10^>6

1Example 1

Input
flowerStick_size = 8, flowerStick = [17, 7, 5, 10, 46, 23, 16, 8], random = 3
Output
[5, 7, 11, 46, 23, 16, 10, 8]
Explanation
Emma has to arrange the first three flower sticks in an increasing order of the length and remaining sticks in the decreasing order of the length. The final order of flower sticks in the bouquet is [5, 7, 11, 46, 23, 16, 10, 8].

Constraints

Limits and guarantees your solution can rely on.

0 ≤ random ≤flowerStick_size
0 < flowerStick_size < 106
public int[] arrangeFlowerSticks(int flowerStick_size, int[] flowerStick, int random) {
  // write your code here
}
Input

flowerStick_size

8

flowerStick

[17, 7, 5, 10, 46, 23, 16, 8]

random

3

Output

[5, 7, 11, 46, 23, 16, 10, 8]

Sign in to submit your solution.