Skip to content

Instantly share code, notes, and snippets.

@enocom
Created May 2, 2015 20:00
Show Gist options
  • Save enocom/b6f2f22a38b72fade904 to your computer and use it in GitHub Desktop.
Save enocom/b6f2f22a38b72fade904 to your computer and use it in GitHub Desktop.
# Here are a handful of good practice problems, some of which may show up in interviews.
# 1. Write an anagram function.
# After that, try writing an anagram function without using #sort and iterating over each word only once
anagram("orchestra", "carthorse") # returns true
anagram("orchestra", "apple") # returns false
# 2. Write a function to test for balanced parentheses.
# This was a Twitter interview question, by the way.
balanced("()") # returns true
balanced(")()") # returns false
# 3. Implement binary search.
# The function should accept a sorted array of integers and a desired integer.
# Return the index of the integer if it appears in the array. Otherwise, return -1
search([1, 2, ... 100], 35) # should return the index of 35
# 4. Write a function that when given an array of sorted integers and a number K,
# returns the number of occurences for K in the array.
count_occurrences([1, 2, 3, 3, 3, 3, 4, 4], 3) # returns 4
count_occurrences([1, 1, 1, 3, 3, 3, 3, 3, 3, 3], 1) # returns 3
# 5. Write a singly linked list
# 6. Write a function to delete a node from a singly linked list
# 7. Write a function to test if a word is a palindrome.
# Now write the same function but do not use #reverse
# 8. Write a function to test if a number is prime
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment