DEV Community

Discussion on: Algorithms Problem Solving: Shuffle the array

Collapse
 
jpantunes profile image
JP Antunes

Not sure if this is idiomatic Python but we can do it in O(n) space and O(log(n)) time ... I think ... :-)

def shuffle(nums, n):
    final_list = []
    for idx in range(n):
        final_list.append(nums[idx])
        final_list.append(nums[n + idx])
    return final_list