Challenge: Reverse First k Elements of Queue

Try to solve the Reverse First k Elements of Queue problem.

We'll cover the following

Statement

Given a queue and a number k, reverse the order of the first k elements in queue. If k is less than 00, if k exceeds queue size, or if queue is empty, return NULL. Otherwise, return the modified queue.

Constraints:

  • 00 \leq queue.length 103\leq 10^{3}
  • 10310^{-3} \leq queue[i] 103\leq 10^{3}
  • 10310^{-3} \leq k 103\leq 10^{3}

Examples

Create a free account to view this lesson.

By signing up, you agree to Educative's Terms of Service and Privacy Policy