-
Implement a stack that supports "max" in O(1) time and O(n) space
-
Implement a queue using two stacks
-
Compress a list of URLs
-
Write a function that detects whether {},(),[] brackets are properly nested. Here "properly" means that an inner pair of brackets must be closed before any outer brackets, a la HTML tags.
-
Write a function to reverse an array in place.
-
Write a function that takes in an amount of money and denominations and returns the number of ways to arrive at the amount with those denominations.
-
Given an array of stockPricesYesterday, indexed by minutes since market open, write an algorithm for finding the maximum profit from a single share (no shorting allowed).
-
Write a function that takes a string with parens and the position of an opening parens and returns the position of the specified opening parens' closing pair.
-
Given an (N+1)-element array in which every integer 1..N appears once except for ONE number which appears twice, return the number which appears twice.
-
Write a function that takes a string as input and checks whether some permutation of the input string is a palindrome. O(n) time and space.
-
Write a function that checks whether a given Binary Tree is a valid Binary Search Tree. O(n) time and space.
-
Given a list of unsorted scores and a highest possible scores, return a sorted list of scores in less than O(nlog(n)) time.
-
Given a function rand7() that returns a random integer from 1 to 7 with equal probability, write a function rand5() that returns a random integer from 1 to 5 with equal probability.
-
Given an array_of_ints, find the highest_product you can get from three of the integers in O(n) time and O(1) space. Can you generalize highest product of 4? Highest product of k for arbitrary k?
-
Write a TemperatureTracker class that supports:
- insert() — records a new temperature
- get_max() — returns the highest temp we've seen so far
- get_min() — returns the lowest temp we've seen so far
- get_mean() — returns the mean of all temps we've seen so far
- get_mode() — returns the mode of all temps we've seen so far
Recorded temperatures are integers and degrees are celsius, always between 0 and 100. Optimize for space and time, favoring the
get_
methods over theinsert
method. If there is more than one mode return an array. You can get O(1) time and space for all methods. -
Given a linked list, detect whether it contains a cycle. Can be done in O(n) time and O(1) space.
-
Given a list of ranges, return a condensed list of ranges, i.e., the smallest list of ranges that encompasses the same total range as the original list. Can be done in O(nlog(n)) time.
-
Write a function that shuffles an array in place.
-
Write a function that takes two rectangles as input and returns a new rectangle representing their intersection. Rectangles are represented as maps containing (x,y,height,width) keys.
-
Write a function that detects whether a given binary tree is balanced or not — can be done in O(n) time and space.
-
Write a recursive function for generating all permutations of an input string, returning them as an array.
-
Given an array of n+1 integers in the range 1..n, write a function that returns a list of all the integers that appear more than once in the input array. Optimize for space - can be done with O(1) space and O(nlog(n)) time without destroying input.
-
Write a function that reverses a linked list. It should take as input the head of the list and return the new head and can run in O(1) space + O(n) time.
-
Given a deck of cards and two "half decks", determine whether the deck of cards could have been produced by a "rifle" of the two halves. Assume the deck contains 52 unique cards, identified by the integers 1..52. O(n) time, O(1) space.
-
Write a function to find the 2nd largest element in a binary search tree.
-
Write a "flight movie picker" function that detects whether there are two movies watchable on a single flight. Function should take an integer flight time and an array of integer movie times (all minutes) and return true/false. Can do in O(n) time and O(n) space.
-
Given a rotated array of alphabetically sorted strings, return the "rotation" point. Can do in O(log(n)) time and O(1) space.
-
Given a sorted array of integers, write a function that checks whether a given integer is in that array. Can be done in O(1) space and O(log(n)) time.