Suppose you have an array of 99 numbers. The array contains the digits 1 to 100 with one digit missing. Describe four different algorithms to compute the missing number. Two of these should optimize for low storage and two of these should optimize for fast processing.
Ruby Performance Interview Questions
- Describe how you would store a social graph in a relational database.
- Describe an efficient algorithm to determine whether or not person X is a 2nd degree connection of person Y.
- Describe an efficient algorithm to determine whether or not person X is a 3rd degree connection of person Y.
- How can you make #3 very quick. E.g. how does Linked In compute 3rd degree connections quickly?
Write a string to find a substring in a given string. Do this in O(n) or better
What is a hashtable? Give an example of a type of problem that a hashtable is useful for.
Explain big o notation and how it is useful in computer science to classify algorithms.
- What order is a hash table lookup?
- What order is determining if a number is even or odd?
- What order is finding an item in an unsorted list?
- What order is a binary search?
For the data structures: Array and Linked List explain:
- Where you might use them
- Operations that are commonly supported (add, insert etc)
Implement a function with signature find_chars(string1, string2) that takes two strings and returns a string that contains only the characters found in string1 and string two in the order that they are found in string1. Implement a version of order N*N and one of order N.
Given a circular list of integers (when you reach the end of the list you come back to the beginning), what is the most efficient algorithm to find the smallest integer in the list?
For example: circular_list = [22, 52, 66, 82, 5, 8, 12, 19].
Write a function to efficiently determine the result of a game of Tic Tac Toe.
The function takes as input the game and the sign (x or o) of the player. The function returns if this player has won the game or not.
Carefully consider both the data structure and the algorithm for your answer.
Efficiently calculate the shortest distance between two Facebook users given an API endpoint that returns all friends of a given user.
Given any integer, efficiently find the next highest integer that uses the same digits.
For example if the number is 15432, you should return 21345.
Given two arrays of strings, A and B.
B contains every element in A, and has one additional member, for example:
* A = ['dog', 'cat', 'monkey]
* B = ['cat', 'rat', 'dog', 'monkey']
Write a function to find the extra string in B. Do this in O(n)
Express the following table as a static structure, and write a function, find_routes(source, destination) that efficiently outputs all possible routes.
Source | Dest
~~~~~~ ~~~~
Seattle | LA
LA | Florida
LA | Maine
Florida | Seattle
Seattle | Florida
The solution for find_routes('Seattle', 'Florida') should be [Seattle -> Florida, Seattle -> LA -> Florida]
The least common multiple of a set of integers is the smallest positive integer that is a multiple of all of the integers in the set.
Write a function that takes an array of integers and efficiently calculates and returns the LCM.
Write function that takes a binary tree and efficiently returns the Nth smallest element.
For example, if N=4, and the tree looks like:
3
/ \
2 5
/ / \
1 4 6
The function should return 4.