Arrange Flower Sticks
Updated
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 interview questions
- Organization Reputation After Employee DeparturesOA · Seen Nov 2026
- Remove Vowels from a StringOA · Seen Nov 2026
- Minimum Deletion Cost for Distinct Adjacent CharactersOA · Seen Oct 2026
- Maximum 69 NumberONSITE INTERVIEW · Seen Oct 2026
- Second Distinct Largest ElementONSITE INTERVIEW · Seen Oct 2026
- Distinct Products After Removing One ElementOA · Seen Sep 2026
- Minimum Cleaning Robot RunsOA · Seen Sep 2026
- Minimum Satellite Data Transfer IterationsOA · Seen Aug 2026
- Find ID of SoldierOA · Seen Jun 2026
- Find Most Frequently Purchased ProductsOA · Seen Jun 2026
Similar questions at other companies
- Build the Task HierarchyPendo · OA
- Closest NumbersHeadlands Technologies · OAHeadlands Technologies interview questions
- Macaron Order with Set DiscountsShopify · OAShopify interview questions
- Count User Mentions in Chat MessagesRamp · OARamp interview questions
- Catch Fish with Reusable BaitsSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
- Competition Winner and Runner-Up (Forward Deployed Engineer)Boston Consulting Group · OABoston Consulting Group interview questions
- Word Frequency Counts in Alphabetical OrderAbridge · OAAbridge interview questions
- Rank Football TeamsCapital One · OACapital One interview questions
- Maximum Apples That Fit in a BoxVirtu Financial · OAVirtu Financial interview questions
- Rank Football TeamsPersona · OAPersona interview questions