BETA

Difficulty Level:

Easy

Total Submissions: 111 Accuracy:

45.05%

[Reverse First K elements of Queue (Function Problem)]
       

Given an integer k and a queue of integers, we need to reverse the order of the first k elements of the queue, leaving the other elements in the same relative order.

Only following standard operations are allowed on queue.

  • enqueue(x) : Add an item x to rear of queue
  • dequeue() : Remove an item from front of queue
  • size(( : Returns number of elements in queue.
  • front() : Finds front item.
     

Example:

Input : Q = [10, 20, 30, 40, 50, 60, 
            70, 80, 90, 100]
        k = 5
Output : Q = [50, 40, 30, 20, 10, 60, 
             70, 80, 90, 100]

Input:
First line consists of T test cases. First line of every test case consists of 2 integers, N and K, denoting number of elements and number of elements to be reversed respectively. Second line of every test case consists of elements of array.

Output:
Single line output, print the modified queue.

Constraints:
1<=T<=100
1<=N<=1000
1<=K<=N

Example:
Input:

1
5 3
1 2 3 4 5
Output:
3 2 1 4 5 

Note:The Input/Ouput format and Example given are used for system's internal purpose, and should be used by a user for Expected Output only. As it is a function problem, hence a user should not read any input from stdin/console. The task is to complete the function specified, and not to write the full code.

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Saksham Raj Seth


					   
It is recommended to 'Compile & Test' your code before clicking 'Submit'!

Compilation/Execution Result:

Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.