anmolk18 / mod-1-whiteboard-challenge-move-zeroes-and-two-sum

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

web-week-2-cs-problem

For the next 30 minutes take turns with the person sitting next to you whiteboarding out solutions to the two following problems. Try to only use Ruby documentation as an outside resource.

Problem1

"Given an array of numbers, write the method move_zeroes() method to move all 0's to the end of it while maintaining the relative order of the non-zero elements.

For example, given nums = [0, 1, 0, 3, 12], after calling your method, nums should be [1, 3, 12, 0, 0].

def move_zeroes(nums)

end

Array sorted before and after

Problem2

"Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number.

The method two_sum should return the indices of the two numbers such that they add up to the target, where index1 must be less than index2.

You may assume that each input would have exactly one solution.

Input: numbers=[2, 7, 11, 15], target=9 Output: {index1: 0, index2: 1}"

def two_sum(numbers, target)

end

About