Challenge 3: Reversing First "k" Elements of Queue

Can you reverse the first "k" elements in a given queue?

Problem statement

Implement the function myQueue reverseK(myQueue queue, int k), which takes a queue and a number k as input and reverses the first k elements of the queue.

Input

The input is a queue and an integer k such that 0 \leq k\leq size of the queue.

Output

Queue with the first k elements reversed is the output.

Sample input

Queue = [1,2,3,4,5,6,7,8,9,10]    k = 5

Sample output

result = [5,4,3,2,1,6,7,8,9,10]

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.