Challenge: Shuffle Integers
In this lesson, we will solve a challenge on shuffling a list of 2n integers without using extra space.
We'll cover the following...
We'll cover the following...
Shuffle integers
Suppose you have a list of size (size of the list is a multiple of 2) arranged as:
In the context of this problem, we will call this array shuffled if its elements were to get re-arranged like this:
Problem statement:
Given a list of integers of size and taking all the boundary cases in consideration, shuffle the list, without using extra space.
Input
lst(list of integers)
Output
lst(shuffled list if the size of the list is in , otherwise the same list)
Sample input
lst = [1, 2, 3, 4, 5, 6, 7, 8]
Sample output
lst = [1, 5, 2, 6, 3, 7, 4, 8]
Coding challenge
First, take a close look at this problem and design a step-by-step algorithm before jumping to the implementation. This problem is designed for your practice, so try to solve it on your own first. If you get stuck, you can always refer to the solution provided in the solution section. Good luck!