-
Notifications
You must be signed in to change notification settings - Fork 2
Home
These interview questions was asked by Google:
-
codechallenge_001.py: Given a list of numbers and a number k, return whether any two numbers from the list add up to k. For example, given
[10, 15, 3, 7]
and k of 17, return true since 10 + 7 is 17. -
codechallenge_003.py: Given the root to a binary tree, implement serialize(root), which serializes the tree into a string, and deserialize(s), which deserializes the string back into the tree.
-
codechallenge_006.py: Given an array of integers and a number k, where 1 <= k <= length of the array, compute the maximum values of each subarray of length k.
For example, given array = [10, 5, 2, 7, 8, 7]
and k = 3
,
we should get: [10, 7, 8, 8]
, since:
10 = max(10, 5, 2)
7 = max(5, 2, 7)
8 = max(2, 7, 8)
8 = max(7, 8, 7)
Do this in O(n) time and O(k) space. You can modify the input array in-place
and you do not need to store the results.
You can simply print them out as you compute them.
- codechallenge_009.py: Given two singly linked lists that intersect at some point, find the intersecting node. The lists are non-cyclical.
For example, given
A = 3 -> 7 -> 8 -> 10
and
B = 99 -> 1 -> 8 -> 10
,
return the node with value 8.
- codechallenge_011.py: You are given an M by N matrix consisting of booleans that represents a board. Each True boolean represents a wall. Each False boolean represents a tile you can walk on.
Given this matrix, a start coordinate, and an end coordinate, return the minimum number of steps required to reach the end coordinate from the start. If there is no possible path, then return null. You can move up, left, down, and right. You cannot move through walls. You cannot wrap around the edges of the board.
- codechallenge_015.py: Given a singly linked list and an integer k, remove the kth last element from the list. k is guaranteed to be smaller than the length of the list.
The list is very long, so making more than one pass is prohibitively expensive.
- codechallenge_016.py: Given two strings, compute the edit distance between them.
The edit distance between two strings refers to the minimum number of character insertions, deletions, and substitutions required to change one string to the other. For example, the edit distance between 'kitten' and 'sitting' is three: substitute the 'k' for 's', substitute the 'e' for 'i', and append a 'g'.
- codechallenge_020.py: Given an array of strictly the characters 'R', 'G', and 'B', segregate the values of the array so that all the Rs come first, the Gs come second, and the Bs come last. You can only swap elements of the array.
Do this in linear time and in-place.
For example, given the array ['G', 'B', 'R', 'R', 'B', 'R', 'G']
,
it should become ['R', 'R', 'R', 'G', 'G', 'B', 'B']
.
- codechallenge_010.py: Given a dictionary of words and a string made up of those words (no spaces), return the original sentence in a list. If there is more than one possible reconstruction, return any of them. If there is no possible reconstruction, then return null.
For example, given the set of words 'quick', 'brown', 'the', 'fox', and the
string "thequickbrownfox", you should return ['the', 'quick', 'brown', 'fox']
.
Given the set of words 'bed', 'bath', 'bedbath', 'and', 'beyond', and the
string "bedbathandbeyond", return either ['bed', 'bath', 'and', 'beyond]
or ['bedbath', 'and', 'beyond']
.
- codechallenge_018.py: Compute the running median of a sequence of numbers. That is, given a stream of numbers, print out the median of the list so far on each new element.
Recall that the median of an even-numbered list is the average of the two middle numbers.
For example, given the sequence [2, 1, 5, 7, 2, 0, 5]
, your algorithm should print out:
2
1.5
2
3.5
2
2
2
Suggestions can be directed to [email protected]