Arranging of flower sticks in a bouquet problem | faceprep

Arranging of flower sticks in a bouquet problem | faceprep

Emma wants to gift a bouquet to her father on his birthday and asked 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 her to arrange the first K flower sticks in the order of their increasing length and the remaining sticks in the order of their decreasing length.

Arranging of flower sticks in a bouquet problem

Write an algorithm to find the final arrangement of the flower sticks in which Emma gifted the bouquet to her father.

Input:

The input to the function/method consists of three arguments.

  • num, an integer representing the number of flower sticks (N).
  • random, an integer representing the number K given by Rosy to Emma sticks
  • a list of integers representing the length of flower sticks.

Output:

Return a list of integers representing the final pattern of the flower sticks in which Emma gifted the bouquet to her father

Constraints:

Random < num

0 < num < 106


Arranging of flower sticks in a bouquet problem

Algorithm:

The logic is to print the elements in a sorted way up to kth value. Then print the remaining elements in reverse order.


For Example:



Arranging of flower sticks in a bouquet problem


Arranging of flower sticks in a bouquet problem | C, C++, Java and Python


Asked in recruitment drive of Wipro.n


@@coding::1@@


Arranging of flower sticks in a bouquet problem


Arranging of flower sticks in a bouquet problem

c