Skip to content

Instantly share code, notes, and snippets.

@futureperfect
Last active September 4, 2019 03:16
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save futureperfect/11016201 to your computer and use it in GitHub Desktop.
Save futureperfect/11016201 to your computer and use it in GitHub Desktop.
Collection of small, interesting programming exercises
Hey,
This is collection of small, interesting interview practice problems.
Hope you get some utility out of this.
Erik
Given a binary tree and two nodes A and B from within that tree, write a function to find the node which is the first common ancestor of A and B
Write a function that finds the mode in an array of numbers.
The mode is the number which occurs the most within a collection.
e.g.
findMode([1, 3, 4, 2, 1, 1, 1] => 1
Given a binary search tree, write a function that returns a list of all nodes at a certain depth D.
Write a function that prints the numbers from 1 to 100. EXCEPT:
* If the number if a multiple of 3, print "Fizz" instead of the number
* If the number is a multiple of 5, print "Buzz" instead of the number
* If the number is a multiple of 3 AND 5, print "FizzBuzz" instead of the number
Write a function that determines if two strings are anagrams of eachother.
e.g.
anagram("FOO", "FOO") => true
anagram("FOO", "BAR") => false
anagram("MARY", "ARMY") => true
anagram("MARRY", "ARMY") => false
Hint: Consider what the essential quality is that makes two words anagrams of each other.
Given a collection of points on a 2D Cartesian plane (i.e. points with an x and y coordinate where axes intersect at 0), write a function to find the k points nearest to the origin.
Write a function that takes as input two sorted arrays of numbers and returns an array which is the combination of the two arrays, also sorted.
e.g.
merge([1, 2, 5, 5, 10], [3, 7, 10, 11]) => [1, 2, 3, 5, 5, 10, 10, 11]
Write a function to mirror a binary tree.
Write a function that reverses a string.
e.g.
reverse("bicycle") => "elcycib"
While I'm pleased if you're aware of standard library functions to do so, let's pretend they don't exist for the moment and do the work to write it.
Hint: Worth considering is whether your language has immutable strings or not and how that changes how you might answer this question.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment