Created
August 18, 2020 21:21
-
-
Save bparanj/dea69b3205ddaa05b4b286e752937999 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# @param {Integer[]} nums | |
# @param {Integer} n | |
# @return {Integer[]} | |
def shuffle(nums, n) | |
result = [] | |
first = 0 | |
second = n | |
index = 0 | |
while result.size < 2*n | |
result[index] = nums[first] | |
first += 1 | |
index += 1 | |
result[index] = nums[second] | |
second += 1 | |
index += 1 | |
end | |
result | |
end | |
nums = [2,5,1,3,4,7] | |
n = 3 | |
p shuffle(nums, n) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Find the relationship between the given input parameters. This relationship is used in the terminating condition of the while loop.