Day 3 LeetCode
👨‍💻

Day 3 LeetCode

Tags
Data Structures
Python
Java
Computer Science
Published
Jan 24, 2021

Day 3 Task:

→ Shuffle the Array:
 

Solutions:

Please review the solution and try implementing on your own if you haven’t gotten it.
 
class Solution:
    '''
    1470. Shuffle the Array: https://leetcode.com/problems/shuffle-the-array/
    
    Solution Approach: Since the array contains 2n elements, if xi is an element, then xi + n will be yn.

    '''
    def shuffle(self, nums: List[int], n: int) -> List[int]:
        ans = []
        for i in range(n):
            ans.append(nums[i])
            ans.append(nums[i+n])
        return ans
 
 
 

Github Link: