""" 1470.1 - Solution 1 - Simulation (Extra Space) """
#####################################################################################
# Imports
#####################################################################################
from typing import List
#####################################################################################
# Classes
#####################################################################################
class Solution:
"""Solution Class"""
def shuffle(self, nums: List[int], n: int) -> List[int]:
"""Shuffle the Array Function"""
result = []
for i in range(n):
result.append(nums[i])
result.append(nums[i + n])
return result
#####################################################################################
# Functions
#####################################################################################
def testcase():
"""Test Function"""
print(Solution().shuffle([2, 5, 1, 3, 4, 7], 3))
print(Solution().shuffle([1, 2, 3, 4, 4, 3, 2, 1], 4))
print(Solution().shuffle([1, 1, 2, 2], 2))
#####################################################################################
# Main
#####################################################################################
if __name__ == "__main__":
testcase()
""" 1470.2 - Solution 2 - Using zip() and List Comprehension """
#####################################################################################
# Imports
#####################################################################################
from typing import List
#####################################################################################
# Classes
#####################################################################################
class Solution:
"""Solution Class"""
def shuffle(self, nums: List[int], n: int) -> List[int]:
"""Shuffle the Array Function"""
return [val for pair in zip(nums[:n], nums[n:]) for val in pair]
#####################################################################################
# Functions
#####################################################################################
def testcase():
"""Test Function"""
print(Solution().shuffle([2, 5, 1, 3, 4, 7], 3))
print(Solution().shuffle([1, 2, 3, 4, 4, 3, 2, 1], 4))
print(Solution().shuffle([1, 1, 2, 2], 2))
#####################################################################################
# Main
#####################################################################################
if __name__ == "__main__":
testcase()