HackStack_ArraysProblems
HackStack_ArraysProblems
Given N, write a function that returns the number of unique ways you can climb
the staircase. The order of the steps matters.
1, 1, 1, 1
2, 1, 1
1, 2, 1
1, 1, 2
2, 2
*
What if, instead of being able to climb 1 or 2 steps at a time, you could climb
any number from a set of positive integers X? For example, if X = {1, 3, 5}, you
could climb 1, 3, or 5 steps at a time. Generalize your function to take in X.
Q2. Given an array of integers, return a new array such that each element at index
i of the new array is the product of all the numbers in the original array except the
one at i.
For example, if our input was [ 1, 2, 3, 4, 5], the expected output would be [ 120,
60, 40, 30, 24]. If our input was [3, 2, 1], the expected output would be [2, 3, 6].
*
What if you can't use division?
Q3. Given an array of integers that are out of order, determine the bounds of the
smallest window that must be sorted in order for the entire array to be sorted. For
example, given [3, 7, 5, 6, 9], you should return (1, 3)
Q4. Given an array of numbers: find the maximum sum of any contiguous
subarray of the array. For example, given the array [34, -50, 42, 14, -5, 86], the
maximum sum would be 137, since we would take elements 42, 14, -5, and 86.
Given the array [ -5, -1, -8, -9], the maximum sum would be 0, since we would
choose not to take any elements. Do this in O (n) time.
*
What if the elements can wrap around? For example, given [ 8, -1, 3, 4], return
15, as we choose the numbers 3, 4, and 8 where the 8 is obtained from wrapping
around.
Q5. Given an array of integers, return a new array where each element in the new
array is the number of smaller elements to the right of that element in the original
input array. For example, given the array [ 3, 4, 9, 6, 1], return [ 1, 1, 2, 1, 0],
since: There is 1 smaller element to the right of 3, There is 1 smaller element to
the right of 4, There are 2 smaller elements to the right of 9, There is 1 smaller
element to the right of 6, There are no smaller elements to the right of 1