Problem · Array

Arrange Flower Sticks

Learn this problem
EasyHSBCOA

Problem statement

Emma wishes to give her father a bouquet for his birthday. Her mother, Rosy, gives her N flower sticks and asks her to arrange them in a particular order. The first K flower sticks must be sorted by increasing length, and the remaining flower sticks must be sorted by decreasing length.

Return the final arrangement of the flower sticks.

Input: flowerStick_size is the number of flower sticks, flowerStick contains their lengths, and random is the value K.

Output: Return the N flower stick lengths in their final order.

Function

arrangeFlowerSticks(flowerStick_size: int, flowerStick: int[], random: int) → int[]

Examples

Example 1

flowerStick_size = 8flowerStick = [11, 7, 5, 10, 46, 23, 16, 8]random = 3return = [5, 7, 11, 46, 23, 16, 10, 8]

Sort the first three lengths [11, 7, 5] in increasing order to obtain [5, 7, 11]. Sort the remaining lengths [10, 46, 23, 16, 8] in decreasing order to obtain [46, 23, 16, 10, 8].

The final arrangement is [5, 7, 11, 46, 23, 16, 10, 8].

Constraints

0 ≤ random ≤flowerStick_size
0 < flowerStick_size < 106

More HSBC problems

drafts saved locally
public int[] arrangeFlowerSticks(int flowerStick_size, int[] flowerStick, int random) {
  // write your code here
}
flowerStick_size8
flowerStick[11, 7, 5, 10, 46, 23, 16, 8]
random3
expected[5, 7, 11, 46, 23, 16, 10, 8]
checking account