Skip to content

Instantly share code, notes, and snippets.

@seemaullal
Last active August 29, 2015 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seemaullal/dc9b81f8ee45cfa7eb83 to your computer and use it in GitHub Desktop.
Save seemaullal/dc9b81f8ee45cfa7eb83 to your computer and use it in GitHub Desktop.
Algorithms 7/16

Level 1
Create a function called removeVowels() to remove all the vowels in a given string. Both uppercase and lowercase vowels should be removed. Your input will be a string and you should return the string without any vowels.

Level 2
Write a function that takes in a 2-D array that represents a square matrix and returns the product of the diagonal of the matrix. For example [ [ 2, 3], [ 4, 5] ] will return 10 (2x5).

Level 3
Design a stack that support the normal stack operations( push(), pop(), peek(), and isEmpty() ) but also has a function called getMin() which returns the value of the minimum element in the stack. All functions should run in constant ( (O(1) ) time.

Level 4
Write a function that accepts as input an array of integers and then returns the length of the longest consecutive range of integers that appear somewhere in that array. For example, [16, 6, 12, 5, 4, 10, 2, 11, 13, 3, 15], it should return 5 (2,3,4,5,6 are all in the array so the longest range of consecutive numbers is 5). What if you wanted to actually return the numbers in the longest range (for example, for this example, you would return [2,3,4,5,6]). Analyze the time and space efficiency of your algorithm.

Level 5
Given an input string and a dictionary of words, split the input string into a space-separated sequence of dictionary words if possible. For example, if the input string is "thisisafunproblem" and the dictionary contains a standard set of English words,then we would return the string "this is a fun problem."

Level 6
Given a number n, generate all distinct ways to write n as the sum of positive integers. For example, with n = 4, the options are 4, 3 + 1, 2 + 2, 2 + 1 + 1, and 1 + 1 + 1 + 1. (Note that 3+1 and 1+3 are considered the same and thus only 3+1 is a part of the result).

You can output your results as an array of strings (["4","3+4", "2+2", "2+1+1", "1+1+1+1"]).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment