mirror of
https://github.com/yangshun/tech-interview-handbook.git
synced 2026-02-03 02:24:47 +08:00
Restructure preparation section
This commit is contained in:
@@ -31,15 +31,10 @@ Arrays
|
||||
- [Source](http://blog.gainlo.co/index.php/2016/07/19/3sum/).
|
||||
- Given an array of numbers list out all quadruplets that sum to 0. Do so with a running time of less than O(n^4).
|
||||
- Given an array of integers, move all the zeroes to the end while preserving the order of the other elements. You have to do it in-place and are not allowed to use any extra storage.
|
||||
- Given a list of people, and a function `knows(a, b)` that returns `true`/`false` if person `a` knows the person `b`. Write a function that finds a VIP, which everybody knows and he doesn't know anybody else.
|
||||
- Given an array of integers, find the subarray with the largest sum. Can you do it in linear time.
|
||||
- Maximum subarray sum problem.
|
||||
- You have an array with the heights of an island (at point 1, point 2 etc) and you want to know how much water would remain on this island (without flowing away).
|
||||
- Trapping rain water question.
|
||||
- Given a sequence of tasks like `A, B, C` (means 3 different tasks), and a cold time, which means you need to wait for that much time to start the next same task, output the best task-finishing sequence.
|
||||
- E.g. input: `AAABBB, 2`, output: `AB_AB_AB` ( `_` represents do nothing and wait)
|
||||
- You are given a list of dominoes. Determine if any two of those dominoes add up to `[6, 6]`.
|
||||
- E.g. `[1, 4]` + `[5, 2]`).
|
||||
- Given an array containing only digits `0-9`, add one to the number and return the array.
|
||||
- E.g. Given `[1, 4, 2, 1]` which represents `1421`, return `[1, 4, 2, 2]` which represents `1422`.
|
||||
- Find the second maximum value in an array.
|
||||
|
||||
@@ -22,6 +22,4 @@ Dynamic Programming
|
||||
// [3, 6, 4] => 7
|
||||
// [4, 10, 3, 1, 5] => 15
|
||||
~~~
|
||||
- How many string representations are there for an integer where `a->1, b->2, ... z->26`.
|
||||
- E.g. `26 => 2`. Because `26` can be encoded as `"z"` and `"bf"`.
|
||||
- Given a list of denominations (e.g., `[1, 2, 5]` means you have coins worth $1, $2, and $5) and a target number `k`, find all possible combinations, if any, of coins in the given denominations that add up to `k`. You can use coins of the same denomination more than once.
|
||||
|
||||
@@ -4,9 +4,7 @@ Graph
|
||||
- Given a list of sorted words from an alien dictionary, find the order of the alphabet.
|
||||
- Alien Dictionary Topological Sort question.
|
||||
- Find if a given string matches any path in a labeled graph. A path may contain cycles.
|
||||
- Given a friendship graph (an undirected graph where nodes represent people and edges means two people know each other), find all your 2nd degree connections (friends’ friends). Output these 2nd degree connections ranked by number of common friends (i.e 1st degree connections) with you, (example: if 2nd degree connection A has 10 common friends (1st degree connections) with you but 2nd degree connection B has 8 common friends (1st degree connections) with you, then A should be ranked first).
|
||||
- Given a bipartite graph, separate the vertices into two sets.
|
||||
- Given a list of email addresses, and a similarity function which says whether two email addresses are similar, write a function to separate the list into sets of email addresses that are similar to each other.
|
||||
- You are a thief trying to sneak across a rectangular field. There are alarms placed on the fields and they each have a circular sensing radius which will trigger if anyone steps into it. Each alarm may not have the same radius. Determine if you can get from one end of the field to the other end.
|
||||
- Given a graph and two nodes, determine if there exists a path between them.
|
||||
- Determine if a cycle exists in the graph.
|
||||
|
||||
@@ -8,10 +8,8 @@ Sorting and Searching
|
||||
- Search for an element in a sorted and rotated array.
|
||||
- [Source](http://blog.gainlo.co/index.php/2017/01/12/rotated-array-binary-search/)
|
||||
- Sort a list where each element is no more than k positions away from its sorted position.
|
||||
- If you have `N` revisions of a program, write a program that will find and return the first bad revision given a `isBad(revision i)` function.
|
||||
- Search for an item in a sorted, but rotated, array.
|
||||
- Merge two sorted lists together.
|
||||
- Given a list of numbers and a function that returns Low, Medium, or High, sort the list by Lows, then Mediums, then Highs.
|
||||
- Give 3 distinct algorithms to find the K largest values in a list of N items.
|
||||
- Find the minimum element in a sorted rotated array in faster than O(n) time.
|
||||
- Write a function that takes a number as input and outputs the biggest number with the same set of digits.
|
||||
|
||||
@@ -24,15 +24,12 @@ String
|
||||
- Given a string, find the longest substring without repeating characters. For example, for string `'abccdefgh'`, the longest substring is `'cdefgh'`.
|
||||
- [Source](http://blog.gainlo.co/index.php/2016/10/07/facebook-interview-longest-substring-without-repeating-characters/)
|
||||
- Given a string, return the string with duplicate characters removed.
|
||||
- How many string representations are there for an integer where `a->1, b->2, ... z->26`.
|
||||
- E.g. `126` can be `'az'` or `'abf'`.
|
||||
- Write a function that receives a regular expression (allowed chars = from `'a'` to `'z'`, `'*'`, `'.'`) and a string containing lower case english alphabet characters and return `true` or `false` whether the string matches the regex.
|
||||
- E.g. `'ab*a'`, `'abbbbba'` => `true`.
|
||||
- E.g. `'ab*b.'`, `'aba'` => `true`.
|
||||
- E.g. `'abc*'`, `'acccc'` => `false`.
|
||||
- Given a rectangular grid with letters, search if some word is in the grid.
|
||||
- Given two strings representing integer numbers (`'123'` , `'30'`) return a string representing the sum of the two numbers: `'153'`.
|
||||
- Given a really big file with a lots of Facebook posts, find the ten most-used words.
|
||||
- A professor wants to see if two students have cheated when writing a paper. Design a function `hasCheated(String s1, String s2, int N)` that evaluates to `true` if two strings have a common substring of length `N`.
|
||||
- Follow up: Assume you don't have the possibility of using `String.contains()` and `String.substring()`. How would you implement this?
|
||||
- Print all permutations of a given string.
|
||||
|
||||
@@ -15,7 +15,6 @@ Tree
|
||||
- Given a directory of files and folders (and relevant functions), how would you parse through it to find equivalent files?
|
||||
- Write a basic file system and implement the commands ls, pwd, mkdir, create, rm, cd, cat, mv.
|
||||
- Compute the intersection of two binary search trees.
|
||||
- Given a tree, where the parent has any number of nodes and each node has a number, return the average of all the nodes on each level in an array.
|
||||
- Given a binary tree, output all the node to leaf paths of it.
|
||||
- Given a string of characters without spaces, is there a way to break the string into valid words without leftover characters?
|
||||
- Print a binary tree level by level.
|
||||
|
||||
Reference in New Issue
Block a user