commit
43b7026c29
@ -0,0 +1,3 @@
|
||||
github: [yangshun]
|
||||
open_collective: tech-interview-handbook
|
||||
custom: https://www.buymeacoffee.com/yangshun
|
@ -0,0 +1,8 @@
|
||||
tasks:
|
||||
- command: gp await-port 3000 && gp preview $(gp url 3000)/tech-interview-handbook/
|
||||
- before: cd website/
|
||||
init: yarn install
|
||||
command: yarn start
|
||||
ports:
|
||||
- port: 3000
|
||||
onOpen: ignore
|
@ -0,0 +1,8 @@
|
||||
{
|
||||
"bracketSpacing": false,
|
||||
"jsxBracketSameLine": true,
|
||||
"printWidth": 80,
|
||||
"proseWrap": "never",
|
||||
"singleQuote": true,
|
||||
"trailingComma": "all"
|
||||
}
|
@ -1,46 +1,3 @@
|
||||
# Contributor Covenant Code of Conduct
|
||||
# Code of Conduct
|
||||
|
||||
## Our Pledge
|
||||
|
||||
In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
||||
|
||||
## Our Standards
|
||||
|
||||
Examples of behavior that contributes to creating a positive environment include:
|
||||
|
||||
* Using welcoming and inclusive language
|
||||
* Being respectful of differing viewpoints and experiences
|
||||
* Gracefully accepting constructive criticism
|
||||
* Focusing on what is best for the community
|
||||
* Showing empathy towards other community members
|
||||
|
||||
Examples of unacceptable behavior by participants include:
|
||||
|
||||
* The use of sexualized language or imagery and unwelcome sexual attention or advances
|
||||
* Trolling, insulting/derogatory comments, and personal or political attacks
|
||||
* Public or private harassment
|
||||
* Publishing others' private information, such as a physical or electronic address, without explicit permission
|
||||
* Other conduct which could reasonably be considered inappropriate in a professional setting
|
||||
|
||||
## Our Responsibilities
|
||||
|
||||
Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
|
||||
|
||||
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
|
||||
|
||||
## Scope
|
||||
|
||||
This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
|
||||
|
||||
## Enforcement
|
||||
|
||||
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at tay.yang.shun@gmail.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
|
||||
|
||||
Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
|
||||
|
||||
## Attribution
|
||||
|
||||
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
|
||||
|
||||
[homepage]: http://contributor-covenant.org
|
||||
[version]: http://contributor-covenant.org/version/1/4/
|
||||
We have adopted the same Code of Conduct as Facebook that we expect project participants to adhere to. Please read [the full text](https://code.facebook.com/codeofconduct) so that you can understand what actions will and will not be tolerated.
|
||||
|
@ -0,0 +1,7 @@
|
||||
## Contributing
|
||||
|
||||
When contributing to this repository, if it is a non-trivial change, please first discuss the change you wish to make via creating an issue in this repository.
|
||||
|
||||
As much as possible, try to follow the existing format of markdown and code. JavaScript code should adopt [Standard style](https://standardjs.com/).
|
||||
|
||||
Please note we have a Code of Conduct, please follow it in all your interactions with the project.
|
@ -1,60 +0,0 @@
|
||||
Arrays
|
||||
==
|
||||
|
||||
- In an array of arrays, e.g. given `[[], [1, 2, 3], [4, 5], [], [], [6, 7], [8], [9, 10], [], []]`, print: `1, 2, 3, 4, 5, 6, 7, 8, 9, 10`.
|
||||
- Implement an iterator that supports `hasNext()`, `next()` and `remove()` methods.
|
||||
- Given a list of item prices, find all possible combinations of items that sum a particular value `K`.
|
||||
- Paginate an array with constraints, such as skipping certain items.
|
||||
- Implement a circular buffer using an array.
|
||||
- Given array of arrays, sort them in ascending order.
|
||||
- Given an array of integers, print out a histogram of using said array; include a base layer (all stars)
|
||||
- E.g. `[5, 4, 0, 3, 4, 1]`
|
||||
|
||||
```
|
||||
*
|
||||
** *
|
||||
** **
|
||||
** **
|
||||
** ***
|
||||
******
|
||||
```
|
||||
|
||||
- Given an array and an index, find the product of the elements of the array except the element at that index.
|
||||
- Given a set of rectangles represented by a height and an interval along the y-axis, determine the size of its union.
|
||||
- Given 2 separate arrays, write a method to find the values that exist in both arrays and return them.
|
||||
- Given an array of integers find whether there is a sub-sequence that sums to 0 and return it.
|
||||
- E.g. `[1, 2, -3, 1]` => `[1, 2, -3]` or `[2, -3, 1]`.
|
||||
- Given an input array and another array that describes a new index for each element, mutate the input array so that each element ends up in their new index. Discuss the runtime of the algorithm and how you can be sure there would not be any infinite loops.
|
||||
- Given an array of non-negative numbers, find continuous subarray with sum to S.
|
||||
- [Source](http://blog.gainlo.co/index.php/2016/06/01/subarray-with-given-sum/).
|
||||
- Given an array of numbers list out all triplets that sum to 0. Do so with a running time of less than O(n^3).
|
||||
- [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 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 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.
|
||||
- Given an array, find the longest arithmetic progression.
|
||||
- Rotate an array by an offset of k.
|
||||
- Remove duplicates in an unsorted array where the duplicates are at a distance of k or less from each other.
|
||||
- Given an unsorted list of integers, return true if the list contains any duplicates within k indices of each element. Do it faster than O(n^2).
|
||||
- Given an unsorted list of integers, return true if the list contains any fuzzy duplicates within k indices of each element. A fuzzy duplicate is another integer within d of the original integer. Do it faster than O(n^2).
|
||||
- E.g. If d = 4, then 6 is a fuzzy duplicate of 3 but 8 is not.
|
||||
- Say you have an unordered list of numbers ranging from 1 to n, and one of the numbers is removed, how do you find that number? What if two numbers are removed?
|
||||
- Given an array of string, find the duplicated elements.
|
||||
- [Source](http://blog.gainlo.co/index.php/2016/05/10/duplicate-elements-of-an-array/).
|
||||
- Given an array of integers, find a maximum sum of non-adjacent elements.
|
||||
- E.g. `[1, 0, 3, 9, 2]` should return `10 (1 + 9)`.
|
||||
- [Source](http://blog.gainlo.co/index.php/2016/12/02/uber-interview-question-maximum-sum-non-adjacent-elements/)
|
||||
- Given an array of integers, modify the array by moving all the zeros to the end (right side). The order of other elements doesn't matter.
|
||||
- E.g. `[1, 2, 0, 3, 0, 1, 2]`, the program can output `[1, 2, 3, 1, 2, 0, 0]`.
|
||||
- [Source](http://blog.gainlo.co/index.php/2016/11/18/uber-interview-question-move-zeroes/).
|
||||
- Given an array, return the length of the longest increasing contiguous subarray.
|
||||
- E.g., `[1, 3, 2, 3, 4, 8, 7, 9]`, should return `4` because the longest increasing array is `[2, 3, 4, 8]`.
|
||||
- [Source](http://blog.gainlo.co/index.php/2017/02/02/uber-interview-questions-longest-increasing-subarray/).
|
||||
- Given an array of integers where every value appears twice except one, find the single, non-repeating value. Follow up: do so with O(1) space.
|
||||
- E.g., `[2, 5, 3, 2, 1, 3, 4, 5, 1]` returns 4, because it is the only value that appears in the array only once.
|
@ -1,7 +0,0 @@
|
||||
Bit Manipulation
|
||||
==
|
||||
|
||||
- How do you verify if an interger is a power of 2?
|
||||
- Wirte a program to print the binary representation of an integer.
|
||||
- Write a program to print out the number of 1 bits in a given integer.
|
||||
- Write a program to determine the largest possible integer using the same number of 1 bits in a given number.
|
@ -1,26 +0,0 @@
|
||||
Dynamic Programming
|
||||
==
|
||||
|
||||
- Given a flight itinerary consisting of starting city, destination city, and ticket price (2D list) - find the optimal price flight path to get from start to destination. (A variation of Dynamic Programming Shortest Path)
|
||||
- Given some coin denominations and a target value `M`, return the coins combination with the minimum number of coins.
|
||||
- Time complexity: `O(MN)`, where N is the number of distinct type of coins.
|
||||
- Space complexity: `O(M)`.
|
||||
- Given a set of numbers in an array which represent a number of consecutive days of Airbnb reservation requested, as a host, pick the sequence which maximizes the number of days of occupancy, at the same time, leaving at least a 1-day gap in-between bookings for cleaning.
|
||||
- The problem reduces to finding the maximum sum of non-consecutive array elements.
|
||||
- E.g.
|
||||
~~~
|
||||
// [5, 1, 1, 5] => 10
|
||||
The above array would represent an example booking period as follows -
|
||||
// Dec 1 - 5
|
||||
// Dec 5 - 6
|
||||
// Dec 6 - 7
|
||||
// Dec 7 - 12
|
||||
|
||||
The answer would be to pick Dec 1-5 (5 days) and then pick Dec 7-12 for a total of 10 days of
|
||||
occupancy, at the same time, leaving at least 1-day gap for cleaning between reservations.
|
||||
|
||||
Similarly,
|
||||
// [3, 6, 4] => 7
|
||||
// [4, 10, 3, 1, 5] => 15
|
||||
~~~
|
||||
- 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.
|
@ -1,7 +0,0 @@
|
||||
Geometry
|
||||
==
|
||||
|
||||
- You have a plane with lots of rectangles on it, find out how many of them intersect.
|
||||
- Which data structure would you use to query the k-nearest points of a set on a 2D plane?
|
||||
- Given many points, find k points that are closest to the origin.
|
||||
- How would you triangulate a polygon?
|
@ -1,10 +0,0 @@
|
||||
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 bipartite graph, separate the vertices into two sets.
|
||||
- You are a thief trying to sneak across a rectangular 100 x 100m 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 has its own 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.
|
@ -1,5 +0,0 @@
|
||||
Heap
|
||||
==
|
||||
|
||||
- Merge `K` sorted lists together into a single list.
|
||||
- Given a stream of integers, write an efficient function that returns the median value of the integers.
|
@ -1,28 +0,0 @@
|
||||
Interval
|
||||
==
|
||||
|
||||
- Given a list of schedules, provide a list of times that are available for a meeting.
|
||||
```
|
||||
[
|
||||
[[4,5], [6,10], [12,14]],
|
||||
[[4,5], [5,9], [13,16]],
|
||||
[[11,14]]
|
||||
]
|
||||
|
||||
Example Output:
|
||||
[[0,4], [11,12], [16,23]]
|
||||
```
|
||||
- You have a number of meetings (with their start and end times). You need to schedule them using the minimum number of rooms. Return the list of meetings in every room.
|
||||
- Interval ranges:
|
||||
- Given 2 interval ranges, create a function to tell me if these ranges intersect. Both start and end are inclusive: `[start, end]`
|
||||
- E.g. `[1, 4]` and `[5, 6]` => `false`
|
||||
- E.g. `[1, 4]` and `[3, 6]` => `true`
|
||||
- Given 2 interval ranges that intersect, now create a function to merge the 2 ranges into a single continuous range.
|
||||
- E.g. `[1, 4]` and `[3, 6]` => `[1, 6]`
|
||||
- Now create a function that takes a group of unsorted, unorganized intervals, merge any intervals that intersect and sort them. The result should be a group of sorted, non-intersecting intervals.
|
||||
- Now create a function to merge a new interval into a group of sorted, non-intersecting intervals. After the merge, all intervals should remain
|
||||
non-intersecting.
|
||||
- Given a list of meeting times, check if any of them overlap. The follow-up question is to return the minimum number of rooms required to accommodate all the meetings.
|
||||
- [Source](http://blog.gainlo.co/index.php/2016/07/12/meeting-room-scheduling-problem/)
|
||||
- If you have a list of intervals, how would you merge them?
|
||||
- E.g. `[1, 3], [8, 11], [2, 6]` => `[1, 6], [8-11]`
|
@ -1,12 +0,0 @@
|
||||
Linked List
|
||||
==
|
||||
|
||||
- Given a linked list, in addition to the next pointer, each node has a child pointer that can point to a separate list. With the head node, flatten the list to a single-level linked list.
|
||||
- [Source](http://blog.gainlo.co/index.php/2016/06/12/flatten-a-linked-list/)
|
||||
- Reverse a singly linked list. Implement it recursively and iteratively.
|
||||
- Convert a binary tree to a doubly circular linked list.
|
||||
- Implement an LRU cache with O(1) runtime for all its operations.
|
||||
- Check distance between values in linked list.
|
||||
- A question involving an API's integration with hash map where the buckets of hash map are made up of linked lists.
|
||||
- Given a singly linked list (a list which can only be traversed in one direction), find the item that is located at 'k' items from the end. So if the list is a, b, c, d and k is 2 then the answer is 'c'. The solution should not search the list twice.
|
||||
- How can you tell if a Linked List is a Palindrome?
|
@ -1,20 +0,0 @@
|
||||
Math
|
||||
==
|
||||
|
||||
- Create a square root function.
|
||||
- Given a string such as "123" or "67", write a function to output the number represented by the string without using casting.
|
||||
- Make a program that can print out the text form of numbers from 1 - 1000 (ex. 20 is "twenty", 105 is "one hundred and five").
|
||||
- Write a function that parses Roman numerals.
|
||||
- E.g. `XIV` returns `14`.
|
||||
- Write in words for a given digit.
|
||||
- E.g. `123` returns `one hundred and twenty three`.
|
||||
- Given a number `N`, find the largest number just smaller than `N` that can be formed using the same digits as `N`.
|
||||
- Compute the square root of `N` without using any existing functions.
|
||||
- Given numbers represented as binary strings, and return the string containing their sum.
|
||||
- E.g. `add('10010', '101')` returns `'10111'`.
|
||||
- Take in an integer and return its english word-format.
|
||||
- E.g. 1 -> "one", -10,203 -> "negative ten thousand two hundred and three".
|
||||
- Write a function that returns values randomly, according to their weight. Suppose we have 3 elements with their weights: A (1), B (1) and C (2). The function should return A with probability 25%, B with 25% and C with 50% based on the weights.
|
||||
- [Source](http://blog.gainlo.co/index.php/2016/11/11/uber-interview-question-weighted-random-numbers/)
|
||||
- Given a number, how can you get the next greater number with the same set of digits?
|
||||
- [Source](http://blog.gainlo.co/index.php/2017/01/20/arrange-given-numbers-to-form-the-biggest-number-possible/)
|
@ -1,18 +0,0 @@
|
||||
Matrix
|
||||
==
|
||||
|
||||
- You're given a 3 x 3 board of a tile puzzle, with 8 tiles numbered 1 to 8, and an empty spot. You can move any tile adjacent to the empty spot, to the empty spot, creating an empty spot where the tile originally was. The goal is to find a series of moves that will solve the board, i.e. get `[[1, 2, 3], [4, 5, 6], [7, 8, - ]]` where - is the empty tile.
|
||||
- Boggle implementation. Given a dictionary, and a matrix of letters, find all the words in the matrix that are in the dictionary. You can go across, down or diagonally.
|
||||
- The values of the matrix will represent numbers of carrots available to the rabbit in each square of the garden. If the garden does not have an exact center, the rabbit should start in the square closest to the center with the highest carrot count. On a given turn, the rabbit will eat the carrots available on the square that it is on, and then move up, down, left, or right, choosing the square that has the most carrots. If there are no carrots left on any of the adjacent squares, the rabbit will go to sleep. You may assume that the rabbit will never have to choose between two squares with the same number of carrots. Write a function which takes a garden matrix and returns the number of carrots the rabbit eats. You may assume the matrix is rectangular with at least 1 row and 1 column, and that it is populated with non-negative integers. For example,
|
||||
- Example: `[[5, 7, 8, 6, 3], [0, 0, 7, 0, 4], [4, 6, 3, 4, 9], [3, 1, 0, 5, 8]]` should return `27`.
|
||||
- Print a matrix in a spiral fashion.
|
||||
- In the Game of life, calculate how to compute the next state of the board. Follow up was to do it if there were memory constraints (board represented by a 1 TB file).
|
||||
- Grid Illumination: Given an NxN grid with an array of lamp coordinates. Each lamp provides illumination to every square on their x axis, every square on their y axis, and every square that lies in their diagonal (think of a Queen in chess). Given an array of query coordinates, determine whether that point is illuminated or not. The catch is when checking a query all lamps adjacent to, or on, that query get turned off. The ranges for the variables/arrays were about: 10^3 < N < 10^9, 10^3 < lamps < 10^9, 10^3 < queries < 10^9.
|
||||
- You are given a matrix of integers. Modify the matrix such that if a row or column contains a 0, make the values in the entire row or column 0.
|
||||
- Given an N x N matrix filled randomly with different colors (no limit on what the colors are), find the total number of groups of each color - a group consists of adjacent cells of the same color touching each other.
|
||||
- You have a 4 x 4 board with characters. You need to write a function that finds if a certain word exists in the board. You can only jump to neighboring characters (including diagonally adjacent).
|
||||
- Count the number of islands in a binary matrix of 0's and 1's.
|
||||
- Check a 6 x 7 Connect 4 board for a winning condition.
|
||||
- Given a fully-filled Sudoku board, check whether fulfills the Sudoku condition.
|
||||
- Implement a function that checks if a player has won tic-tac-toe.
|
||||
- Given an N x N matrix of 1's and 0's, figure out if all of the 1's are connected.
|
@ -1,58 +0,0 @@
|
||||
String
|
||||
==
|
||||
|
||||
- Output list of strings representing a page of hostings given a list of CSV strings.
|
||||
- Given a list of words, find the word pairs that when concatenated form a palindrome.
|
||||
- Find the most efficient way to identify what character is out of place in a non-palindrome.
|
||||
- Implement a simple regex parser which, given a string and a pattern, returns a boolean indicating whether the input matches the pattern. By simple, we mean that the regex can only contain the following special characters: `*` (star), `.` (dot), `+` (plus). The star means that there will be zero or more of the previous character in that place in the pattern. The dot means any character for that position. The plus means one or more of previous character in that place in the pattern.
|
||||
- Find all words from a dictionary that are x edit distance away.
|
||||
- Given a string IP and number n, print all CIDR addresses that cover that range.
|
||||
- Write a function called `eval`, which takes a string and returns a boolean. This string is allowed 6 different characters: `0`, `1`, `&`, `|`, `(`, and `)`. `eval` should evaluate the string as a boolean expression, where `0` is `false`, `1` is `true`, `&` is an `and`, and `|` is an `or`.
|
||||
- E.g `"(0 | (1 | 0)) & (1 & ((1 | 0) & 0))"`
|
||||
- Given a pattern string like `"abba"` and an input string like `"redbluebluered"`, return `true` if and only if there's a one to one mapping of letters in the pattern to substrings of the input.
|
||||
- E.g. `"abba"` and `"redbluebluered"` should return `true`.
|
||||
- E.g. `"aaaa"` and `"asdasdasdasd"` should return `true`.
|
||||
- E.g. `"aabb"` and `"xyzabcxzyabc"` should return `false`.
|
||||
- If you received a file in chunks, calculate when you have the full file. Quite an open-ended question. Can assume chunks come with start and end, or size, etc.
|
||||
- Given a list of names (strings) and the width of a line, design an algorithm to display them using the minimum number of lines.
|
||||
- Design a spell-checking algorithm.
|
||||
- Count and say problem.
|
||||
- Longest substring with `K` unique characters.
|
||||
- [Source](http://blog.gainlo.co/index.php/2016/04/12/find-the-longest-substring-with-k-unique-characters/)
|
||||
- Given a set of random strings, write a function that returns a set that groups all the anagrams together.
|
||||
- [Source](http://blog.gainlo.co/index.php/2016/05/06/group-anagrams/)
|
||||
- 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.
|
||||
- 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'`.
|
||||
- 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.
|
||||
- Parse a string containing numbers and `'+'`, `'-'` and parentheses. Evaluate the expression. `-2+(3-5)` should return `-4`.
|
||||
- Output a substring with at most `K` unique characters.
|
||||
- E.g. `'aabc'` and `k` = 2 => `'aab'`.
|
||||
- Ensure that there are a minimum of `N` dashes between any two of the same characters of a string.
|
||||
- E.g. `n = 2, string = 'ab-bcdecca'` => `'ab--bcdec--ca'`.
|
||||
- Find the longest palindrome in a string.
|
||||
- Give the count and the number following in the series.
|
||||
- E.g. `1122344`, next: `21221324`, next: `12112211121214`.
|
||||
- Count and say problem.
|
||||
- Compress a string by grouping consecutive similar questions together:
|
||||
- E.g. `'aaabbbcc' => `'a3b3c2'`.
|
||||
- You have a string consisting of open and closed parentheses, but parentheses may be imbalanced. Make the parentheses balanced and return the new string.
|
||||
- Given a set of strings, return the smallest subset that contains prefixes for every string.
|
||||
- E.g. `['foo', 'foog', 'food', 'asdf']` => `['foo', 'asdf']`.
|
||||
- Write a function that would return all the possible words generated when using a phone (pre-smartphone era) numpad to type.
|
||||
- Given a dictionary and a word, find the minimum number of deletions needed on the word in order to make it a valid word.
|
||||
- [Source](http://blog.gainlo.co/index.php/2016/04/29/minimum-number-of-deletions-of-a-string/)
|
||||
- How to check if a string contains an anagram of another string?
|
||||
- [Source](http://blog.gainlo.co/index.php/2016/04/08/if-a-string-contains-an-anagram-of-another-string/)
|
||||
- Find all k-lettered words from a string.
|
||||
- Given a string of open and close parentheses, find the minimum number of edits needed to balance a string of parentheses.
|
||||
- Run length encoding - Write a string compress function that returns `'R2G1B1'` given `'RRGB'`.
|
||||
- Write a function that finds all the different ways you can split up a word into a concatenation of two other words.
|
@ -1,36 +0,0 @@
|
||||
Tree
|
||||
==
|
||||
|
||||
- Find the height of a tree.
|
||||
- Find the longest path from the root to leaf in a tree.
|
||||
- Find the deepest left leaf of a tree.
|
||||
- Print all paths of a binary tree.
|
||||
- [Source](http://blog.gainlo.co/index.php/2016/04/15/print-all-paths-of-a-binary-tree/)
|
||||
- Second largest element of a BST.
|
||||
- [Source](http://blog.gainlo.co/index.php/2016/06/03/second-largest-element-of-a-binary-search-tree/)
|
||||
- Given a binary tree and two nodes, how to find the common ancestor of the two nodes?
|
||||
- [Source](http://blog.gainlo.co/index.php/2016/07/06/lowest-common-ancestor/)
|
||||
- Find the lowest common ancestor of two nodes in a binary search tree.
|
||||
- Print the nodes in an n-ary tree level by level, one printed line per level.
|
||||
- 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 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.
|
||||
- Determine if a binary tree is "complete" (i.e, if all leaf nodes were either at the maximum depth or max depth-1, and were 'pressed' along the left side of the tree).
|
||||
- Find the longest path in a binary tree. The path may start and end at any node.
|
||||
- Determine if a binary tree is a BST.
|
||||
- Given a binary tree, serialize it into a string. Then deserialize it.
|
||||
- Print a binary tree by column.
|
||||
- Given a node, find the next element in a BST.
|
||||
- Find the shortest subtree that consist of all the deepest nodes. The tree is not binary.
|
||||
- Print out the sum of each row in a binary tree.
|
||||
- Pretty print a JSON object.
|
||||
- Convert a binary tree to a doubly circular linked list.
|
||||
- Find the second largest number in a binary tree.
|
||||
- Given a tree, find the longest branch.
|
||||
- Convert a tree to a linked list.
|
||||
- Given two trees, write code to find out if tree A is a subtree of tree B.
|
||||
- Deepest node in a tree.
|
||||
- [Source](http://blog.gainlo.co/index.php/2016/04/26/deepest-node-in-a-tree/)
|
Before Width: | Height: | Size: 5.2 KiB |
@ -0,0 +1,49 @@
|
||||
---
|
||||
id: array
|
||||
title: Array
|
||||
---
|
||||
|
||||
## Notes
|
||||
|
||||
Is the array sorted or partially sorted? If it is, some form of binary search should be possible. This also usually means that the interviewer is looking for a solution that is faster than O(n).
|
||||
|
||||
Can you sort the array? Sometimes sorting the array first may significantly simplify the problem. Make sure that the order of array elements do not need to be preserved before attempting a sort.
|
||||
|
||||
For questions where summation or multiplication of a subarray is involved, pre-computation using hashing or a prefix/suffix sum/product might be useful.
|
||||
|
||||
If you are given a sequence and the interviewer asks for O(1) space, it might be possible to use the array itself as a hash table. For example, if the array only has values from 1 to N, where N is the length of the array, negate the value at that index (minus one) to indicate presence of that number.
|
||||
|
||||
Also O(n) doesn't mean you can only traverse the array once. Sometimes traversing the array more than once can help you solve the problem easily.
|
||||
|
||||
## Arrays are sequences
|
||||
|
||||
Are there duplicate values in the array, would it affect the answer?
|
||||
|
||||
When using an index to iterate through array elements, be careful not to go out of bounds.
|
||||
|
||||
Be mindful about slicing or concatenating arrays in your code. Typically, slicing and concatenating arrays require O(n) time. Use start and end indices to demarcate a subarray/range where possible.
|
||||
|
||||
Sometimes you can traverse the array from the right rather than from the left.
|
||||
|
||||
Master the [sliding window technique](https://discuss.leetcode.com/topic/30941/here-is-a-10-line-template-that-can-solve-most-substring-problems) that applies to many subarray problems.
|
||||
|
||||
When you are given two arrays to process, it is common to have one index per array (pointer) to traverse/compare the both of them. For example, we use the same approach to merge two sorted arrays.
|
||||
|
||||
## Corner cases
|
||||
|
||||
- Empty sequence
|
||||
- Sequence with 1 or 2 elements
|
||||
- Sequence with repeated elements
|
||||
|
||||
## Recommended LeetCode questions
|
||||
|
||||
- [Two Sum](https://leetcode.com/problems/two-sum/)
|
||||
- [Best Time to Buy and Sell Stock](https://leetcode.com/problems/best-time-to-buy-and-sell-stock/)
|
||||
- [Contains Duplicate](https://leetcode.com/problems/contains-duplicate/)
|
||||
- [Product of Array Except Self](https://leetcode.com/problems/product-of-array-except-self/)
|
||||
- [Maximum Subarray](https://leetcode.com/problems/maximum-subarray/)
|
||||
- [Maximum Product Subarray](https://leetcode.com/problems/maximum-product-subarray/)
|
||||
- [Find Minimum in Rotated Sorted Array](https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/)
|
||||
- [Search in Rotated Sorted Array](https://leetcode.com/problems/search-in-rotated-sorted-array/)
|
||||
- [3Sum](https://leetcode.com/problems/3sum/)
|
||||
- [Container With Most Water](https://leetcode.com/problems/container-with-most-water/)
|
@ -0,0 +1,33 @@
|
||||
---
|
||||
id: binary
|
||||
title: Binary
|
||||
---
|
||||
|
||||
## Study links
|
||||
|
||||
- [Bits, Bytes, Building With Binary](https://medium.com/basecs/bits-bytes-building-with-binary-13cb4289aafa)
|
||||
|
||||
## Notes
|
||||
|
||||
Questions involving binary representations and bitwise operations are asked sometimes and you must be absolutely familiar with how to convert a number from decimal form into binary form (and vice versa) in your chosen programming language.
|
||||
|
||||
Some helpful utility snippets:
|
||||
|
||||
- Test k<sup>th</sup> bit is set: `num & (1 << k) != 0`.
|
||||
- Set k<sup>th</sup> bit: `num |= (1 << k)`.
|
||||
- Turn off k<sup>th</sup> bit: `num &= ~(1 << k)`.
|
||||
- Toggle the k<sup>th</sup> bit: `num ^= (1 << k)`.
|
||||
- To check if a number is a power of 2, `num & num - 1 == 0`.
|
||||
|
||||
## Corner cases
|
||||
|
||||
- Be aware and check for overflow/underflow
|
||||
- Negative numbers
|
||||
|
||||
## Recommended LeetCode questions
|
||||
|
||||
- [Sum of Two Integers](https://leetcode.com/problems/sum-of-two-integers/)
|
||||
- [Number of 1 Bits](https://leetcode.com/problems/number-of-1-bits/)
|
||||
- [Counting Bits](https://leetcode.com/problems/counting-bits/)
|
||||
- [Missing Number](https://leetcode.com/problems/missing-number/)
|
||||
- [Reverse Bits](https://leetcode.com/problems/reverse-bits/)
|
@ -0,0 +1,17 @@
|
||||
---
|
||||
id: geometry
|
||||
title: Geometry
|
||||
---
|
||||
|
||||
## Notes
|
||||
|
||||
When comparing euclidean distance between two pairs of points, using dx<sup>2</sup> + dy<sup>2</sup> is sufficient. It is unnecessary to square root the value.
|
||||
|
||||
To find out if two circles overlap, check that the distance between the two centers of the circles is less than the sum of their radii.
|
||||
|
||||
## Sample questions
|
||||
|
||||
- You have a plane with lots of rectangles on it, find out how many of them intersect.
|
||||
- Which data structure would you use to query the k-nearest points of a set on a 2D plane?
|
||||
- Given many points, find k points that are closest to the origin.
|
||||
- How would you triangulate a polygon?
|
@ -0,0 +1,113 @@
|
||||
---
|
||||
id: graph
|
||||
title: Graph
|
||||
---
|
||||
|
||||
## Study links
|
||||
|
||||
- [From Theory To Practice: Representing Graphs](https://medium.com/basecs/from-theory-to-practice-representing-graphs-cfd782c5be38)
|
||||
- [Deep Dive Through A Graph: DFS Traversal](https://medium.com/basecs/deep-dive-through-a-graph-dfs-traversal-8177df5d0f13)
|
||||
- [Going Broad In A Graph: BFS Traversal](https://medium.com/basecs/going-broad-in-a-graph-bfs-traversal-959bd1a09255)
|
||||
|
||||
## Notes
|
||||
|
||||
Be familiar with the various graph representations, graph search algorithms and their time and space complexities.
|
||||
|
||||
You can be given a list of edges and tasked to build your own graph from the edges to perform a traversal on. The common graph representations are:
|
||||
|
||||
- Adjacency matrix.
|
||||
- Adjacency list.
|
||||
- Hashmap of hashmaps.
|
||||
|
||||
A tree-like diagram could very well be a graph that allows for cycles and a naive recursive solution would not work. In that case you will have to handle cycles and keep a set of visited nodes when traversing.
|
||||
|
||||
## Graph search algorithms:
|
||||
|
||||
- **Common** - Breadth-first Search, Depth-first Search
|
||||
- **Uncommon** - Topological Sort, Dijkstra's algorithm
|
||||
- **Rare** - Bellman-Ford algorithm, Floyd-Warshall algorithm, Prim's algorithm, Kruskal's algorithm
|
||||
|
||||
In coding interviews, graphs are commonly represented as 2-D matrices where cells are the nodes and each cell can traverse to its adjacent cells (up/down/left/right). Hence it is important that you be familiar with traversing a 2-D matrix. When traversing the matrix, always ensure that your current position is within the boundary of the matrix and has not been visited before.
|
||||
|
||||
A simple template for doing depth-first searches on a matrix goes like this:
|
||||
|
||||
```py
|
||||
def dfs(matrix):
|
||||
# Check for an empty graph.
|
||||
if not matrix:
|
||||
return []
|
||||
|
||||
rows, cols = len(matrix), len(matrix[0])
|
||||
visited = set()
|
||||
directions = ((0, 1), (0, -1), (1, 0), (-1, 0))
|
||||
|
||||
def traverse(i, j):
|
||||
if (i, j) in visited:
|
||||
return
|
||||
|
||||
visited.add((i, j))
|
||||
# Traverse neighbors.
|
||||
for direction in directions:
|
||||
next_i, next_j = i + direction[0], j + direction[1]
|
||||
if 0 <= next_i < rows and 0 <= next_j < cols:
|
||||
# Add in your question-specific checks.
|
||||
traverse(next_i, next_j)
|
||||
|
||||
for i in range(rows):
|
||||
for j in range(cols):
|
||||
traverse(i, j)
|
||||
```
|
||||
|
||||
A similar template for doing breadth-first searches on the matrix goes like this:
|
||||
|
||||
```py
|
||||
from collections import deque
|
||||
|
||||
def bfs(matrix):
|
||||
# Check for an empty graph.
|
||||
if not matrix:
|
||||
return []
|
||||
|
||||
rows, cols = len(matrix), len(matrix[0])
|
||||
visited = set()
|
||||
directions = ((0, 1), (0, -1), (1, 0), (-1, 0))
|
||||
|
||||
def traverse(i, j):
|
||||
queue = deque([(i, j)])
|
||||
while queue:
|
||||
curr_i, curr_j = queue.popleft()
|
||||
if (curr_i, curr_j) not in visited:
|
||||
visited.add((curr_i, curr_j))
|
||||
# Traverse neighbors.
|
||||
for direction in directions:
|
||||
next_i, next_j = curr_i + direction[0], curr_j + direction[1]
|
||||
if 0 <= next_i < rows and 0 <= next_j < cols:
|
||||
# Add in your question-specific checks.
|
||||
queue.append((next_i, next_j))
|
||||
|
||||
for i in range(rows):
|
||||
for j in range(cols):
|
||||
traverse(i, j)
|
||||
```
|
||||
|
||||
> NOTE: While DFS is implemented using recursion in this sample, it could also be implemented iteratively similar to BFS. The key difference between the algorithms lies in the underlying data structure (BFS uses a queue while DFS uses a stack). The `deque` class in Python can function as both a stack and a queue
|
||||
|
||||
For additional tips on BFS and DFS, you can refer to this [LeetCode post](https://leetcode.com/problems/pacific-atlantic-water-flow/discuss/90774/Python-solution-with-detailed-explanation)
|
||||
|
||||
## Corner cases
|
||||
|
||||
- Empty graph
|
||||
- Graph with one or two nodes
|
||||
- Disjoint graphs
|
||||
- Graph with cycles
|
||||
|
||||
## Recommended LeetCode questions
|
||||
|
||||
- [Clone Graph](https://leetcode.com/problems/clone-graph/)
|
||||
- [Course Schedule](https://leetcode.com/problems/course-schedule/)
|
||||
- [Pacific Atlantic Water Flow](https://leetcode.com/problems/pacific-atlantic-water-flow/)
|
||||
- [Number of Islands](https://leetcode.com/problems/number-of-islands/)
|
||||
- [Longest Consecutive Sequence](https://leetcode.com/problems/longest-consecutive-sequence/)
|
||||
- [Alien Dictionary (LeetCode Premium)](https://leetcode.com/problems/alien-dictionary/)
|
||||
- [Graph Valid Tree (LeetCode Premium)](https://leetcode.com/problems/graph-valid-tree/)
|
||||
- [Number of Connected Components in an Undirected Graph (LeetCode Premium)](https://leetcode.com/problems/number-of-connected-components-in-an-undirected-graph/)
|
@ -1,7 +1,10 @@
|
||||
Hash Table
|
||||
==
|
||||
---
|
||||
id: hash-table
|
||||
title: Hash Table
|
||||
---
|
||||
|
||||
## Sample questions
|
||||
|
||||
- Describe an implementation of a least-used cache, and big-O notation of it.
|
||||
- A question involving an API's integration with hash map where the buckets of hash map are made up of linked lists.
|
||||
- Implement data structure `Map` storing pairs of integers (key, value) and define following member functions in O(1) runtime: `void insert(key, value)`, `void delete(key)`, `int get(key)`, `int getRandomKey()`.
|
||||
- [Source](http://blog.gainlo.co/index.php/2016/08/14/uber-interview-question-map-implementation/).
|
||||
- Implement data structure `Map` storing pairs of integers (key, value) and define following member functions in O(1) runtime: `void insert(key, value)`, `void delete(key)`, `int get(key)`, `int getRandomKey()`. [(Solution)](http://blog.gainlo.co/index.php/2016/08/14/uber-interview-question-map-implementation/)
|
@ -0,0 +1,20 @@
|
||||
---
|
||||
id: heap
|
||||
title: Heap
|
||||
---
|
||||
|
||||
## Study links
|
||||
|
||||
- [Learning to Love Heaps](https://medium.com/basecs/learning-to-love-heaps-cef2b273a238)
|
||||
|
||||
## Notes
|
||||
|
||||
If you see a top or lowest _k_ being mentioned in the question, it is usually a signal that a heap can be used to solve the problem, such as in [Top K Frequent Elements](https://leetcode.com/problems/top-k-frequent-elements/).
|
||||
|
||||
If you require the top _k_ elements use a Min Heap of size _k_. Iterate through each element, pushing it into the heap. Whenever the heap size exceeds _k_, remove the minimum element, that will guarantee that you have the _k_ largest elements.
|
||||
|
||||
## Recommended LeetCode questions
|
||||
|
||||
- [Merge K Sorted Lists](https://leetcode.com/problems/merge-k-sorted-lists/)
|
||||
- [Top K Frequent Elements](https://leetcode.com/problems/top-k-frequent-elements/)
|
||||
- [Find Median from Data Stream](https://leetcode.com/problems/find-median-from-data-stream/)
|
@ -0,0 +1,40 @@
|
||||
---
|
||||
id: interval
|
||||
title: Interval
|
||||
---
|
||||
|
||||
## Notes
|
||||
|
||||
Interval questions are questions where you are given an array of two-element arrays (an interval) and the two values represent a start and an end value. Interval questions are considered part of the array family but they involve some common techniques hence they are extracted out to this special section of their own.
|
||||
|
||||
An example interval array: `[[1, 2], [4, 7]]`.
|
||||
|
||||
Interval questions can be tricky to those who have not tried them before because of the sheer number of cases to consider when they overlap.
|
||||
|
||||
Do clarify with the interviewer whether `[1, 2]` and `[2, 3]` are considered overlapping intervals as it affects how you will write your equality checks.
|
||||
|
||||
A common routine for interval questions is to sort the array of intervals by each interval's starting value.
|
||||
|
||||
Be familiar with writing code to check if two intervals overlap and merging two overlapping intervals:
|
||||
|
||||
```py
|
||||
def is_overlap(a, b):
|
||||
return a[0] < b[1] and b[0] < a[1]
|
||||
|
||||
def merge_overlapping_intervals(a, b):
|
||||
return [min(a[0], b[0]), max(a[1], b[1])]
|
||||
```
|
||||
|
||||
## Corner cases
|
||||
|
||||
- Single interval
|
||||
- Non-overlapping intervals
|
||||
- An interval totally consumed within another interval
|
||||
- Duplicate intervals
|
||||
|
||||
## Recommended LeetCode questions
|
||||
|
||||
- [Insert Interval](https://leetcode.com/problems/insert-interval/)
|
||||
- [Merge Intervals](https://leetcode.com/problems/merge-intervals/)
|
||||
- [Non-overlapping Intervals](https://leetcode.com/problems/non-overlapping-intervals/)
|
||||
- [Meeting Rooms (LeetCode Premium)](https://leetcode.com/problems/meeting-rooms/) and [Meeting Rooms II (LeetCode Premium)](https://leetcode.com/problems/meeting-rooms-ii/)
|
@ -0,0 +1,52 @@
|
||||
---
|
||||
id: algorithms-introduction
|
||||
title: Introduction
|
||||
---
|
||||
|
||||
This section dives deep into practical tips for specific topics of algorithms and data structures which appear frequently in coding questions. Many algorithm questions involve techniques that can be applied to questions of similar nature. The more techniques you have in your arsenal, the higher the chances of passing the interview. They may lead you to discover corner cases you might have missed out or even lead you towards the optimal approach!
|
||||
|
||||
For each topic, study links are recommended to help you master the topic. There is a list of recommended common questions to practice which in my opinion is highly valuable for mastering the core concepts for the topic.
|
||||
|
||||
If you are interested in how data structures are implemented, check out [Lago](https://github.com/yangshun/lago), a Data Structures and Algorithms library for JavaScript. It is pretty much still WIP but I intend to make it into a library that is able to be used in production and also a reference resource for revising Data Structures and Algorithms.
|
||||
|
||||
## General tips
|
||||
|
||||
Clarify any assumptions you made subconsciously. Many questions are under-specified on purpose.
|
||||
|
||||
Always validate input first. Check for invalid/empty/negative/different type input. Never assume you are given the valid parameters. Alternatively, clarify with the interviewer whether you can assume valid input (usually yes), which can save you time from writing code that does input validation.
|
||||
|
||||
Are there any time/space complexity requirements/constraints?
|
||||
|
||||
Check for off-by-one errors.
|
||||
|
||||
In languages where there are no automatic type coercion, check that concatenation of values are of the same type: `int`/`str`/`list`.
|
||||
|
||||
After finishing your code, use a few example inputs to test your solution.
|
||||
|
||||
Is the algorithm meant to be run multiple times, for example in a web server? If yes, the input is likely to be preprocess-able to improve the efficiency in each call.
|
||||
|
||||
Use a mix of functional and imperative programming paradigms:
|
||||
|
||||
- Write pure functions as much as possible.
|
||||
- Pure functions are easier to reason about and can help to reduce bugs in your implementation.
|
||||
- Avoid mutating the parameters passed into your function especially if they are passed by reference unless you are sure of what you are doing.
|
||||
- However, functional programming is usually expensive in terms of space complexity because of non-mutation and the repeated allocation of new objects. On the other hand, imperative code is faster because you operate on existing objects. Hence you will need to achieve a balance between accuracy vs efficiency, by using the right amount of functional and imperative code where appropriate.
|
||||
- Avoid relying on and mutating global variables. Global variables introduce state.
|
||||
- If you have to rely on global variables, make sure that you do not mutate it by accident.
|
||||
|
||||
Generally, to improve the speed of a program, we can either: (1) choose a more appropriate data structure/algorithm; or (2) use more memory. The latter demonstrates a classic space vs. time tradeoff, but it is not necessarily the case that you can only achieve better speed at the expense of space. Also, note that there is often a theoretical limit to how fast your program can run (in terms of time complexity). For instance, a question that requires you to find the smallest/largest element in an unsorted array cannot run faster than O(N).
|
||||
|
||||
Data structures are your weapons. Choosing the right weapon for the right battle is the key to victory. Be very familiar about the strengths of each data structure and the time complexities for its various operations.
|
||||
|
||||
Data structures can be augmented to achieve efficient time complexities across different operations. For example, a hash map can be used together with a doubly-linked list to achieve O(1) time complexity for both the `get` and `put` operation in an [LRU cache](https://leetcode.com/problems/lru-cache/).
|
||||
|
||||
Hashmaps are probably the most commonly used data structure for algorithm questions. If you are stuck on a question, your last resort can be to enumerate through the common possible data structures (thankfully there aren't that many of them) and consider whether each of them can be applied to the problem. This has worked for me sometimes.
|
||||
|
||||
If you are cutting corners in your code, state that out loud to your interviewer and say what you would do in a non-interview setting (no time constraints). E.g., I would write a regex to parse this string rather than using `split()` which may not cover all cases.
|
||||
|
||||
###### References
|
||||
|
||||
- http://blog.triplebyte.com/how-to-pass-a-programming-interview
|
||||
- https://quip.com/q41AA3OmoZbC
|
||||
- http://www.geeksforgeeks.org/must-do-coding-questions-for-companies-like-amazon-microsoft-adobe/
|
||||
- https://medium.com/basecs
|
@ -0,0 +1,48 @@
|
||||
---
|
||||
id: linked-list
|
||||
title: Linked List
|
||||
---
|
||||
|
||||
## Notes
|
||||
|
||||
Like arrays, linked lists are used to represent sequential data. The benefit of linked lists is that insertion and deletion of a node in the list (given its location) is O(1) whereas in arrays the following elements will have to be shifted.
|
||||
|
||||
Adding a dummy node at the head and/or tail might help to handle many edge cases where operations have to be performed at the head or the tail. The presence of dummy nodes essentially ensures that operations will never have be done on the head or the tail, thereby removing a lot of headache in writing conditional checks to dealing with null pointers. Be sure to remember to remove them at the end of the operation.
|
||||
|
||||
Sometimes linked lists problem can be solved without additional storage. Try to borrow ideas from reverse a linked list problem.
|
||||
|
||||
For deletion in linked lists, you can either modify the node values or change the node pointers. You might need to keep a reference to the previous element.
|
||||
|
||||
For partitioning linked lists, create two separate linked lists and join them back together.
|
||||
|
||||
Linked lists problems share similarity with array problems, think about how you would do it for an array and try to apply it to a linked list.
|
||||
|
||||
Two pointer approaches are also common for linked lists. For example:
|
||||
|
||||
- Getting the k<sup>th</sup> from last node - Have two pointers, where one is k nodes ahead of the other. When the node ahead reaches the end, the other node is k nodes behind
|
||||
- Detecting cycles - Have two pointers, where one pointer increments twice as much as the other, if the two pointers meet, means that there is a cycle
|
||||
- Getting the middle node - Have two pointers, where one pointer increments twice as much as the other. When the faster node reaches the end of the list, the slower node will be at the middle
|
||||
|
||||
## Common Routines
|
||||
|
||||
Be familiar with the following routines because many linked list questions make use of one or more of these routines in the solution:
|
||||
|
||||
- Counting the number of nodes in the linked list
|
||||
- Reversing a linked list in-place
|
||||
- Finding the middle node of the linked list using fast/slow pointers
|
||||
- Merging two lists together
|
||||
|
||||
## Corner cases
|
||||
|
||||
- Single node
|
||||
- Two nodes
|
||||
- Linked list has cycle. **Tip:** Clarify with the interviewer whether there can be a cycle in the list. Usually the answer is no
|
||||
|
||||
## Recommended LeetCode questions
|
||||
|
||||
- [Reverse a Linked List](https://leetcode.com/problems/reverse-linked-list/)
|
||||
- [Detect Cycle in a Linked List](https://leetcode.com/problems/linked-list-cycle/)
|
||||
- [Merge Two Sorted Lists](https://leetcode.com/problems/merge-two-sorted-lists/)
|
||||
- [Merge K Sorted Lists](https://leetcode.com/problems/merge-k-sorted-lists/)
|
||||
- [Remove Nth Node From End Of List](https://leetcode.com/problems/remove-nth-node-from-end-of-list/)
|
||||
- [Reorder List](https://leetcode.com/problems/reorder-list/)
|
@ -0,0 +1,29 @@
|
||||
---
|
||||
id: math
|
||||
title: Math
|
||||
---
|
||||
|
||||
## Notes
|
||||
|
||||
If code involves division or modulo, remember to check for division or modulo by 0 case.
|
||||
|
||||
When a question involves "a multiple of a number", perhaps modulo might be useful.
|
||||
|
||||
Check for and handle overflow/underflow if you are using a typed language like Java and C++. At the very least, mention that overflow/underflow is possible and ask whether you need to handle it.
|
||||
|
||||
Consider negative numbers and floating point numbers. This may sound obvious, but under interview pressure, many obvious cases go unnoticed.
|
||||
|
||||
If the question asks to implement an operator such as power, squareroot or division and want it to be faster than O(n), binary search is usually the approach to go.
|
||||
|
||||
#### Some common formulas:
|
||||
|
||||
- Sum of 1 to N = (n+1) \* n/2
|
||||
- Sum of GP = 2<sup>0</sup> + 2<sup>1</sup> + 2<sup>2</sup> + 2<sup>3</sup> + ... 2<sup>n</sup> = 2<sup>n+1</sup> - 1
|
||||
- Permutations of N = N! / (N-K)!
|
||||
- Combinations of N = N! / (K! \* (N-K)!)
|
||||
|
||||
## Recommended LeetCode questions
|
||||
|
||||
- [Pow(x, n)](https://leetcode.com/problems/powx-n/)
|
||||
- [Sqrt(x)](https://leetcode.com/problems/sqrtx/)
|
||||
- [Integer to English Words](https://leetcode.com/problems/integer-to-english-words/)
|
@ -0,0 +1,36 @@
|
||||
---
|
||||
id: matrix
|
||||
title: Matrix
|
||||
---
|
||||
|
||||
## Notes
|
||||
|
||||
A matrix is a 2-dimensional array. Questions involving matrices are usually related to dynamic programming or graph traversal.
|
||||
|
||||
For questions involving traversal or dynamic programming, you almost always want to make a copy of the matrix with the same dimensions that is initialized to empty values to store the visited state or dynamic programming table. Be familiar with such a routine:
|
||||
|
||||
```py
|
||||
rows, cols = len(matrix), len(matrix[0])
|
||||
copy = [[0 for _ in range(cols)] for _ in range(rows)]
|
||||
```
|
||||
|
||||
Many grid-based games can be modeled as a matrix, such as Tic-Tac-Toe, Sudoku, Crossword, Connect 4, Battleship, etc. It is not uncommon to be asked to verify the winning condition of the game. For games like Tic-Tac-Toe, Connect 4 and Crosswords, where verification has to be done vertically and horizontally, one trick is to write code to verify the matrix for the horizontal cells, transpose the matrix and reuse the logic for horizontal verification to verify originally vertical cells (which are now horizontal).
|
||||
|
||||
Transposing a matrix in Python is simply:
|
||||
|
||||
```py
|
||||
transposed_matrix = zip(*matrix)
|
||||
```
|
||||
|
||||
## Corner cases
|
||||
|
||||
- Empty matrix. Check that none of the arrays are 0 length
|
||||
- 1 x 1 matrix
|
||||
- Matrix with only one row or column
|
||||
|
||||
## Recommended LeetCode questions
|
||||
|
||||
- [Set Matrix Zeroes](https://leetcode.com/problems/set-matrix-zeroes/)
|
||||
- [Spiral Matrix](https://leetcode.com/problems/spiral-matrix/)
|
||||
- [Rotate Image](https://leetcode.com/problems/rotate-image/)
|
||||
- [Word Search](https://leetcode.com/problems/word-search/)
|
@ -1,8 +1,13 @@
|
||||
Object-Oriented Programming
|
||||
==
|
||||
---
|
||||
id: oop
|
||||
title: Object-Oriented Programming
|
||||
---
|
||||
|
||||
## Sample questions
|
||||
|
||||
- How would you design a chess game? What classes and objects would you use? What methods would they have?
|
||||
- How would you design the data structures for a book keeping system for a library?
|
||||
- Explain how you would design a HTTP server? Give examples of classes, methods, and interfaces. What are the challenges here?
|
||||
- Discuss algorithms and data structures for a garbage collector?
|
||||
- How would you implement an HR system to keep track of employee salaries and benefits?
|
||||
- How would you implement an Elevator system?
|
@ -1,5 +1,9 @@
|
||||
Queue
|
||||
==
|
||||
---
|
||||
id: queue
|
||||
title: Queue
|
||||
---
|
||||
|
||||
## Sample questions
|
||||
|
||||
- Implement a Queue class from scratch with an existing bug, the bug is that it cannot take more than 5 elements.
|
||||
- Implement a Queue using two stacks. You may only use the standard `push()`, `pop()`, and `peek()` operations traditionally available to stacks. You do not need to implement the stack yourself (i.e. an array can be used to simulate a stack).
|
@ -0,0 +1,17 @@
|
||||
---
|
||||
id: recursion
|
||||
title: Recursion
|
||||
---
|
||||
|
||||
## Notes
|
||||
|
||||
Recursion is useful for permutation, because it generates all combinations and tree-based questions. You should know how to generate all permutations of a sequence as well as how to handle duplicates.
|
||||
|
||||
Remember to always define a base case so that your recursion will end.
|
||||
|
||||
Recursion implicitly uses a stack. Hence all recursive approaches can be rewritten iteratively using a stack. Beware of cases where the recursion level goes too deep and causes a stack overflow (the default limit in Python is 1000). You may get bonus points for pointing this out to the interviewer. Recursion will never be O(1) space complexity because a stack is involved, unless there is [tail-call optimization](https://stackoverflow.com/questions/310974/what-is-tail-call-optimization) (TCO). Find out if your chosen language supports TCO.
|
||||
|
||||
## Recommended LeetCode questions
|
||||
|
||||
- [Subsets](https://leetcode.com/problems/subsets/) and [Subsets II](https://leetcode.com/problems/subsets-ii/)
|
||||
- [Strobogrammatic Number II (LeetCode Premium)](https://leetcode.com/problems/strobogrammatic-number-ii/)
|
@ -1,5 +1,9 @@
|
||||
Stack
|
||||
==
|
||||
---
|
||||
id: stack
|
||||
title: Stack
|
||||
---
|
||||
|
||||
## Sample questions
|
||||
|
||||
- Implementation of an interpreter for a small language that does multiplication/addition/etc.
|
||||
- Design a `MinStack` data structure that supports a `min()` operation that returns the minimum value in the stack in O(1) time.
|
@ -1,5 +1,7 @@
|
||||
Topics
|
||||
==
|
||||
---
|
||||
id: topics
|
||||
title: Topics
|
||||
---
|
||||
|
||||
## Arrays
|
||||
|
@ -0,0 +1,61 @@
|
||||
---
|
||||
id: tree
|
||||
title: Tree
|
||||
---
|
||||
|
||||
## Study links
|
||||
|
||||
- [Leaf It Up To Binary Trees](https://medium.com/basecs/leaf-it-up-to-binary-trees-11001aaf746d)
|
||||
|
||||
## Notes
|
||||
|
||||
A tree is an undirected and connected acyclic graph.
|
||||
|
||||
Recursion is a common approach for trees. When you notice that the subtree problem can be used to solve the entire problem, try using recursion.
|
||||
|
||||
When using recursion, always remember to check for the base case, usually where the node is `null`.
|
||||
|
||||
When you are asked to traverse a tree by level, use breadth-first search.
|
||||
|
||||
Sometimes it is possible that your recursive function needs to return two values.
|
||||
|
||||
If the question involves summation of nodes along the way, be sure to check whether nodes can be negative.
|
||||
|
||||
You should be very familiar with writing pre-order, in-order, and post-order traversal recursively. As an extension, challenge yourself by writing them iteratively. Sometimes interviewers ask candidates for the iterative approach, especially if the candidate finishes writing the recursive approach too quickly.
|
||||
|
||||
Do check out the section on [Trie](trie.md), which is an advanced tree.
|
||||
|
||||
## Corner cases
|
||||
|
||||
- Empty tree
|
||||
- Single node
|
||||
- Two nodes
|
||||
- Very skewed tree (like a linked list)
|
||||
|
||||
## Special Trees
|
||||
|
||||
### Binary Tree
|
||||
|
||||
In-order traversal of a binary tree is insufficient to uniquely serialize a tree. Pre-order or post-order traversal is also required.
|
||||
|
||||
### Binary Search Tree (BST)
|
||||
|
||||
In-order traversal of a BST will give you all elements in order.
|
||||
|
||||
Be very familiar with the properties of a BST and validating that a binary tree is a BST. This comes up more often than expected.
|
||||
|
||||
When a question involves a BST, the interviewer is usually looking for a solution which runs faster than O(n).
|
||||
|
||||
#### Recommended LeetCode questions
|
||||
|
||||
- [Maximum Depth of Binary Tree](https://leetcode.com/problems/maximum-depth-of-binary-tree/)
|
||||
- [Same Tree](https://leetcode.com/problems/same-tree/)
|
||||
- [Invert/Flip Binary Tree](https://leetcode.com/problems/invert-binary-tree/)
|
||||
- [Binary Tree Maximum Path Sum](https://leetcode.com/problems/binary-tree-maximum-path-sum/)
|
||||
- [Binary Tree Level Order Traversal](https://leetcode.com/problems/binary-tree-level-order-traversal/)
|
||||
- [Serialize and Deserialize Binary Tree](https://leetcode.com/problems/serialize-and-deserialize-binary-tree/)
|
||||
- [Subtree of Another Tree](https://leetcode.com/problems/subtree-of-another-tree/)
|
||||
- [Construct Binary Tree from Preorder and Inorder Traversal](https://leetcode.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal/)
|
||||
- [Validate Binary Search Tree](https://leetcode.com/problems/validate-binary-search-tree/)
|
||||
- [Kth Smallest Element in a BST](https://leetcode.com/problems/kth-smallest-element-in-a-bst/)
|
||||
- [Lowest Common Ancestor of BST](https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-search-tree/)
|
@ -0,0 +1,23 @@
|
||||
---
|
||||
id: trie
|
||||
title: Trie
|
||||
---
|
||||
|
||||
## Study links
|
||||
|
||||
- [Trying to Understand Tries](https://medium.com/basecs/trying-to-understand-tries-3ec6bede0014)
|
||||
- [Implement Trie (Prefix Tree)](https://leetcode.com/articles/implement-trie-prefix-tree/)
|
||||
|
||||
## Notes
|
||||
|
||||
Tries are special trees (prefix trees) that make searching and storing strings more efficient. Tries have many practical applications, such as conducting searches and providing autocomplete. It is helpful to know these common applications so that you can easily identify when a problem can be efficiently solved using a trie.
|
||||
|
||||
Sometimes preprocessing a dictionary of words (given in a list) into a trie, will improve the efficiency of searching for a word of length k, among n words. Searching becomes O(k) instead of O(n).
|
||||
|
||||
Be familiar with implementing, from scratch, a `Trie` class and its `add`, `remove` and `search` methods.
|
||||
|
||||
## Recommended LeetCode questions
|
||||
|
||||
- [Implement Trie (Prefix Tree)](https://leetcode.com/problems/implement-trie-prefix-tree)
|
||||
- [Add and Search Word](https://leetcode.com/problems/add-and-search-word-data-structure-design)
|
||||
- [Word Search II](https://leetcode.com/problems/word-search-ii/)
|
@ -0,0 +1,107 @@
|
||||
---
|
||||
id: best-practice-questions
|
||||
title: Best Practice Questions
|
||||
---
|
||||
|
||||
Here is a suggested schedule for revising and practicing algorithm questions on [LeetCode](https://leetcode.com). Sign up for an account if you don't already have one, it's critical to your success in interviewing!
|
||||
|
||||
When practicing, you are advised to treat it like a real coding interview and check through thoroughly before submitting. Consider even manually coming up with some test cases and running through them to verify correctness!
|
||||
|
||||
## Week 1 - Sequences
|
||||
|
||||
In week 1, we will start off easy and do a mix of easy and medium questions on arrays and strings. Arrays and strings are the most common types of questions to be found in interviews; gaining familiarity with them will help in building strong fundamentals to better handle tougher questions.
|
||||
|
||||
- [Two Sum](https://leetcode.com/problems/two-sum/)
|
||||
- [Contains Duplicate](https://leetcode.com/problems/contains-duplicate/)
|
||||
- [Best Time to Buy and Sell Stock](https://leetcode.com/problems/best-time-to-buy-and-sell-stock/)
|
||||
- [Valid Anagram](https://leetcode.com/problems/valid-anagram/)
|
||||
- [Valid Parentheses](https://leetcode.com/problems/valid-parentheses/)
|
||||
- [Product of Array Except Self](https://leetcode.com/problems/product-of-array-except-self/)
|
||||
- [Maximum Subarray](https://leetcode.com/problems/maximum-subarray/)
|
||||
- [3Sum](https://leetcode.com/problems/3sum/)
|
||||
- [Merge Intervals](https://leetcode.com/problems/merge-intervals/)
|
||||
- [Group Anagrams](https://leetcode.com/problems/group-anagrams/)
|
||||
|
||||
#### Optional
|
||||
|
||||
- [Maximum Product Subarray](https://leetcode.com/problems/maximum-product-subarray/)
|
||||
- [Search in Rotated Sorted Array](https://leetcode.com/problems/search-in-rotated-sorted-array/)
|
||||
|
||||
## Week 2 - Data Structures
|
||||
|
||||
The focus of week 2 is on linked lists, strings and matrix-based questions. The goal is to learn the common routines dealing with linked lists, traversing matrices and sequence analysis (arrays/strings) techniques such as sliding window.
|
||||
|
||||
- [Reverse a Linked List](https://leetcode.com/problems/reverse-linked-list/)
|
||||
- [Detect Cycle in a Linked List](https://leetcode.com/problems/linked-list-cycle/)
|
||||
- [Container With Most Water](https://leetcode.com/problems/container-with-most-water/)
|
||||
- [Find Minimum in Rotated Sorted Array](https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/)
|
||||
- [Longest Repeating Character Replacement](https://leetcode.com/problems/longest-repeating-character-replacement/)
|
||||
- [Longest Substring Without Repeating Characters](https://leetcode.com/problems/longest-substring-without-repeating-characters/)
|
||||
- [Minimum Window Substring](https://leetcode.com/problems/minimum-window-substring/)
|
||||
- [Number of Islands](https://leetcode.com/problems/number-of-islands/)
|
||||
- [Remove Nth Node From End Of List](https://leetcode.com/problems/remove-nth-node-from-end-of-list/)
|
||||
- [Palindromic Substrings](https://leetcode.com/problems/palindromic-substrings/)
|
||||
- [Pacific Atlantic Water Flow](https://leetcode.com/problems/pacific-atlantic-water-flow/)
|
||||
|
||||
## Week 3 - Non-Linear Data Structures
|
||||
|
||||
The focus of week 3 is on non-linear data structures like trees, graphs and heaps. You should be familiar with the various tree traversal (in-order, pre-order, post-order) algorithms and graph traversal algorithms such as breadth-first search and depth-first search. In my experience, using more advanced graph algorithms (Dijkstra's and Floyd-Warshall) is quite rare and usually not necessary.
|
||||
|
||||
- [Validate Binary Search Tree](https://leetcode.com/problems/validate-binary-search-tree/)
|
||||
- [Invert/Flip Binary Tree](https://leetcode.com/problems/invert-binary-tree/)
|
||||
- [Non-overlapping Intervals](https://leetcode.com/problems/non-overlapping-intervals/)
|
||||
- [Serialize and Deserialize Binary Tree](https://leetcode.com/problems/serialize-and-deserialize-binary-tree/)
|
||||
- [Construct Binary Tree from Preorder and Inorder Traversal](https://leetcode.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal/)
|
||||
- [Top K Frequent Elements](https://leetcode.com/problems/top-k-frequent-elements/)
|
||||
- [Clone Graph](https://leetcode.com/problems/clone-graph/)
|
||||
- [Course Schedule](https://leetcode.com/problems/course-schedule/)
|
||||
- [Binary Tree Maximum Path Sum](https://leetcode.com/problems/binary-tree-maximum-path-sum/)
|
||||
|
||||
#### Optional
|
||||
|
||||
- [Maximum Depth of Binary Tree](https://leetcode.com/problems/maximum-depth-of-binary-tree/)
|
||||
- [Same Tree](https://leetcode.com/problems/same-tree/)
|
||||
- [Binary Tree Level Order Traversal](https://leetcode.com/problems/binary-tree-level-order-traversal/)
|
||||
- [Encode and Decode Strings (LeetCode Premium)](https://leetcode.com/problems/encode-and-decode-strings/)
|
||||
|
||||
## Week 4 - More Data Structures
|
||||
|
||||
Week 4 builds up on knowledge from previous weeks but questions are of increased difficulty. Expect to see such level of questions during interviews. You get more practice on more advanced data structures such as (but not exclusively limited to) heaps and tries.
|
||||
|
||||
- [Add and Search Word](https://leetcode.com/problems/add-and-search-word-data-structure-design/)
|
||||
- [Implement Trie (Prefix Tree)](https://leetcode.com/problems/implement-trie-prefix-tree/)
|
||||
- [Subtree of Another Tree](https://leetcode.com/problems/subtree-of-another-tree/)
|
||||
- [Kth Smallest Element in a BST](https://leetcode.com/problems/kth-smallest-element-in-a-bst/)
|
||||
- [Lowest Common Ancestor of BST](https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-search-tree/)
|
||||
- [Merge K Sorted Lists](https://leetcode.com/problems/merge-k-sorted-lists/)
|
||||
- [Find Median from Data Stream](https://leetcode.com/problems/find-median-from-data-stream/)
|
||||
- [Insert Interval](https://leetcode.com/problems/insert-interval/)
|
||||
- [Longest Consecutive Sequence](https://leetcode.com/problems/longest-consecutive-sequence/)
|
||||
- [Word Search II](https://leetcode.com/problems/word-search-ii/)
|
||||
|
||||
#### Optional
|
||||
|
||||
- [Meeting Rooms (LeetCode Premium)](https://leetcode.com/problems/meeting-rooms/)
|
||||
- [Meeting Rooms II (LeetCode Premium)](https://leetcode.com/problems/meeting-rooms-ii/)
|
||||
- [Alien Dictionary (LeetCode Premium)](https://leetcode.com/problems/alien-dictionary/)
|
||||
- [Graph Valid Tree (LeetCode Premium)](https://leetcode.com/problems/graph-valid-tree/)
|
||||
- [Number of Connected Components in an Undirected Graph (LeetCode Premium)](https://leetcode.com/problems/number-of-connected-components-in-an-undirected-graph/)
|
||||
|
||||
## Week 5 - Dynamic Programming
|
||||
|
||||
Week 5 focuses on Dynamic Programming (DP) questions. Personally as an interviewer, I'm not a fan of DP questions as they are not really applicable to practical scenarios and frankly if I were made to do the tough DP questions during my interviews I'd not have gotten the job. However, companies like Google still ask DP questions and if joining Google is your dream, DP is unavoidable.
|
||||
|
||||
DP questions can be hard to master and the best way to get better at them is... you guessed it - practice! Be familiar with the concepts of memoization and backtracking.
|
||||
|
||||
Practically speaking the return of investment (ROI) on studying and practicing for DP questions is very low. Hence DP questions are less important/optional and you should only do them if you're very keen to have all bases covered.
|
||||
|
||||
- [Climbing Stairs](https://leetcode.com/problems/climbing-stairs/)
|
||||
- [Coin Change](https://leetcode.com/problems/coin-change/)
|
||||
- [Longest Increasing Subsequence](https://leetcode.com/problems/longest-increasing-subsequence/)
|
||||
- [Combination Sum](https://leetcode.com/problems/combination-sum-iv/)
|
||||
- [House Robber](https://leetcode.com/problems/house-robber/)
|
||||
- [House Robber II](https://leetcode.com/problems/house-robber-ii/)
|
||||
- [Decode Ways](https://leetcode.com/problems/decode-ways/)
|
||||
- [Unique Paths](https://leetcode.com/problems/unique-paths/)
|
||||
- [Jump Game](https://leetcode.com/problems/jump-game/)
|
||||
- [Word Break Problem](https://leetcode.com/problems/word-break/)
|
@ -0,0 +1,107 @@
|
||||
---
|
||||
id: cheatsheet
|
||||
title: Cheatsheet
|
||||
---
|
||||
|
||||
This is a straight-to-the-point, distilled list of technical interview Do's and Don'ts, mainly for algorithmic interviews. Some of these may apply to only phone screens or whiteboard interviews, but most will apply to both. I revise this list before each of my interviews to remind myself of them and eventually internalized all of them to the point I do not have to rely on it anymore.
|
||||
|
||||
#### Legend
|
||||
|
||||
- ✅ = Do
|
||||
- ❌ = Don't
|
||||
- ⚠️ = Situational
|
||||
|
||||
### Before interview
|
||||
|
||||
| | Things |
|
||||
| --- | --- |
|
||||
| ✅ | Prepare pen, paper and earphones/headphones. |
|
||||
| ✅ | Find a quiet environment with good Internet connection. |
|
||||
| ✅ | Ensure webcam and audio are working. There were times I had to restart Chrome to get Hangouts to work again. |
|
||||
| ✅ | Request for the option to interview over Hangouts/Skype instead of a phone call; it is easier to send links or text across. |
|
||||
| ✅ | Decide on and be familiar with a programming language. |
|
||||
| ✅ | Familiarize yourself with the coding environment (CoderPad/CodePen). Set up the coding shortcuts, turn on autocompletion, tab spacing, etc. |
|
||||
| ✅ | Prepare answers to the [frequently-asked behavioral questions](behavioral-questions.md) in an interview. |
|
||||
| ✅ | Prepare some [questions to ask](questions-to-ask.md) at the end of the interview. |
|
||||
| ✅ | Dress comfortably. Usually you do not need to wear smart clothes, casual should be fine. T-shirts and jeans are acceptable at most places. |
|
||||
| ✅ | Stay calm and composed. |
|
||||
| ⚠️ | Turn off the webcam if possible. Most remote interviews will not require video chat and leaving it on only serves as a distraction. |
|
||||
|
||||
### Introduction
|
||||
|
||||
| | Things |
|
||||
| --- | --- |
|
||||
| ✅ | Introduce yourself in a few sentences under a minute or two. |
|
||||
| ✅ | Mention interesting points that are relevant to the role you are applying for. |
|
||||
| ✅ | Sound enthusiastic! Speak with a smile and you will naturally sound more engaging. |
|
||||
| ❌ | Spend too long introducing yourself. The more time you spend talking the less time you have to code. |
|
||||
|
||||
### Upon receiving the question
|
||||
|
||||
| | Things |
|
||||
| --- | --- |
|
||||
| ✅ | Repeat the question back at the interviewer. |
|
||||
| ✅ | Clarify any assumptions you made subconsciously. Many questions are under-specified on purpose. E.g. a tree-like diagram could very well be a graph that allows for cycles and a naive recursive solution would not work. |
|
||||
| ✅ | Clarify input format and range. Ask whether input can be assumed to be well-formed and non-null. |
|
||||
| ✅ | Work through a small example to ensure you understood the question. |
|
||||
| ✅ | Explain a high level approach even if it is a brute force one. |
|
||||
| ✅ | Improve upon the approach and optimize. Reduce duplicated work and cache repeated computations. |
|
||||
| ✅ | Think carefully, then state and explain the time and space complexity of your approaches. |
|
||||
| ✅ | If stuck, think about related problems you have seen before and how they were solved. Check out the [tips](algorithms/introduction.md) in this section. |
|
||||
| ❌ | Ignore information given to you. Every piece is important. |
|
||||
| ❌ | Jump into coding straightaway. |
|
||||
| ❌ | Start coding without interviewer's green light. |
|
||||
| ❌ | Appear too unsure about your approach or analysis. |
|
||||
|
||||
### During coding
|
||||
|
||||
| | Things |
|
||||
| --- | --- |
|
||||
| ✅ | Explain what you are coding/typing to the interviewer, what you are trying to achieve. |
|
||||
| ✅ | Practice good coding style. Clear variable names, consistent operator spacing, proper indentation, etc. |
|
||||
| ✅ | Type/write at a reasonable speed. |
|
||||
| ✅ | As much as possible, write actual compilable code, not pseudocode. |
|
||||
| ✅ | Write in a modular fashion. Extract out chunks of repeated code into functions. |
|
||||
| ✅ | Ask for permission to use trivial functions without having to implement them; saves you some time. |
|
||||
| ✅ | Use the hints given by the interviewer. |
|
||||
| ✅ | Demonstrate mastery of your chosen programming language. |
|
||||
| ✅ | Demonstrate technical knowledge in data structures and algorithms. |
|
||||
| ✅ | If you are cutting corners in your code, state that out loud to your interviewer and say what you would do in a non-interview setting (no time constraints). E.g., "Under non-interview settings, I would write a regex to parse this string rather than using `split()` which may not cover all cases." |
|
||||
| ✅ | Practice whiteboard space-management skills. |
|
||||
| ⚠️ | Reasonable defensive coding. Check for nulls, empty collections, etc. Can omit if input validity has been clarified with the interviewer. |
|
||||
| ❌ | Remain quiet the whole time. |
|
||||
| ❌ | Spend too much time writing comments. |
|
||||
| ❌ | Use extremely verbose or single-character (unless they're common like `i`, `n`) variable names. |
|
||||
| ❌ | Copy and paste code without checking (e.g. variables need to be renamed). |
|
||||
| ❌ | Interrupt your interviewer when they are talking. Usually if they speak, they are trying to give you hints or steer you in the right direction. |
|
||||
| ❌ | Write too big (takes up too much space) or too small (illegible) if on a whiteboard. |
|
||||
|
||||
### After coding
|
||||
|
||||
| | Things |
|
||||
| --- | --- |
|
||||
| ✅ | Scan through your code for mistakes as if it was your first time seeing code written by someone else. |
|
||||
| ✅ | Check for off-by-one errors. |
|
||||
| ✅ | Come up with more test cases. Try extreme test cases. |
|
||||
| ✅ | Step through your code with those test cases. |
|
||||
| ✅ | Look out for places where you can refactor. |
|
||||
| ✅ | Reiterate the time and space complexity of your code. |
|
||||
| ✅ | Explain trade-offs and how the code/approach can be improved if given more time. |
|
||||
| ❌ | Immediately announce that you are done coding. Do the above first! |
|
||||
| ❌ | Argue with the interviewer. They may be wrong but that is very unlikely given that they are familiar with the question. |
|
||||
|
||||
### Wrap up
|
||||
|
||||
| | Things |
|
||||
| --- | --- |
|
||||
| ✅ | Ask questions. More importantly, ask good and engaging questions that are tailored to the company! Pick some questions from [this list](questions-to-ask.md). |
|
||||
| ✅ | Thank the interviewer. |
|
||||
| ⚠️ | Ask about your interview performance. It can get awkward. |
|
||||
| ❌ | End the interview without asking any questions. |
|
||||
|
||||
### Post interview
|
||||
|
||||
| | Things |
|
||||
| --- | --- |
|
||||
| ✅ | Record the interview questions and answers down as these can be useful for future reference. |
|
||||
| ⚠️ | Send a follow up email to your interviewer(s) thanking them for their time and the opportunity to interview with them. |
|
@ -0,0 +1,14 @@
|
||||
---
|
||||
id: coding-round-overview
|
||||
title: Overview
|
||||
---
|
||||
|
||||
Coding interviews are tough. But fortunately, there's a tried and proven method to get better at them. With a combination of studying, practicing questions and doing mock interviews, getting that dream job can become a reality.
|
||||
|
||||
1. Decide on a programming language
|
||||
1. Study CS fundamentals
|
||||
1. Practice solving algorithm questions
|
||||
1. Internalize the [Do's and Don'ts of interviews](./cheatsheet.md)
|
||||
1. Know what [signals and behaviors](./coding-signals.md) interviewers are looking out for
|
||||
1. Practice doing mock interviews
|
||||
1. Interview successfully to get the job
|
@ -0,0 +1,96 @@
|
||||
---
|
||||
id: coding-signals
|
||||
title: Coding Signals
|
||||
---
|
||||
|
||||
The point of interviews is for interviewers to extract signals from certain candidate behaviors. In coding interviews, the signals can be broadly classified into the following categories: Problem Solving, Technical Competency, Testing, and Communication.
|
||||
|
||||
When interviewers take down interview feedback, these are likely what is on their feedback sheet.
|
||||
|
||||
## Problem solving
|
||||
|
||||
#### Understanding the problem
|
||||
|
||||
- 👍 Understood the key aspects of the problem quickly
|
||||
- 👎 Had difficulty in understanding the key aspects of the problem
|
||||
|
||||
#### Solution/approach
|
||||
|
||||
- 👍 Approached the problem in a systematic and logical manner
|
||||
- 👎 Did not demonstrate a logical thought process for approaching the problem
|
||||
|
||||
#### Improving the solution
|
||||
|
||||
- 👍 Suggested a more efficient solution when prompted, or proactively coming up with a better solution
|
||||
- 👎 Had difficulty in coming up with a more efficient solution even after being prompted
|
||||
|
||||
#### Trade-offs analysis
|
||||
|
||||
- 👍 Explained the trade-offs of different approaches clearly and correctly
|
||||
- 👎 Failed to describe trade-offs of different approaches
|
||||
|
||||
#### Hinting
|
||||
|
||||
- 👍 Did not require any major hints
|
||||
- 👎 Needed plenty of hints
|
||||
|
||||
## Technical competency
|
||||
|
||||
#### Speed
|
||||
|
||||
- 👍 Quickly implemented a working solution
|
||||
- 👎 Was not able to complete the solution
|
||||
|
||||
#### Correctness/Accuracy
|
||||
|
||||
- 👍 Implemented the solution correctly (e.g., working solution, minimal bugs)
|
||||
- 👎 Unable to correctly implement a solution (e.g., non-working solution, incorrect logic, and/or serious bugs)
|
||||
|
||||
#### Complexity analysis
|
||||
|
||||
- 👍 Able to determine the algorithmic time and space complexity
|
||||
- 👎 Was not able to determine the algorithmic time and space complexity (explain why TC came up with such an answer)
|
||||
|
||||
#### Mastery of chosen programming language
|
||||
|
||||
- 👍 Demonstrated mastery of the chosen programming language
|
||||
- 👎 Does not seem to be familiar with the chosen programming language
|
||||
|
||||
#### Implementation
|
||||
|
||||
- 👍 Implementation was clean and straightforward
|
||||
- 👎 Implementation was unnecessarily complex and/or messy
|
||||
|
||||
#### Coding style
|
||||
|
||||
- 👍 Coding style was neat (proper indentation, spacing and no bad practices)
|
||||
- 👎 Coding style was messy (inconsistent indentation, weird spacings, etc)
|
||||
|
||||
## Testing
|
||||
|
||||
#### Common cases
|
||||
|
||||
- 👍 Tested their code against various typical cases
|
||||
- 👎 Failed to test the code against typical cases
|
||||
|
||||
#### Corner cases
|
||||
|
||||
- 👍 Found and handled corner/edge cases
|
||||
- 👎 Failed to consider corner/edge cases
|
||||
|
||||
#### Self-correction
|
||||
|
||||
- 👍 Identified and corrected bugs in the code (where applicable)
|
||||
- 👎 Was not able to discover and fix bugs even after being prompted
|
||||
|
||||
## Communication
|
||||
|
||||
#### Clarify problem
|
||||
|
||||
- 👍 Appropriately asked good, clarifying questions about the problem
|
||||
- 👎 Failed to confirm understanding/ask appropriate questions
|
||||
|
||||
#### Communicating approach
|
||||
|
||||
- 👍 Able to explain overall approach, technical terms and acronyms (where applicable)
|
||||
- 👎 Failed to effectively explain overall approach, technical terms and acronyms (where applicable)
|
@ -1,5 +1,7 @@
|
||||
Cover Letter
|
||||
==
|
||||
---
|
||||
id: cover-letter
|
||||
title: Cover Letter
|
||||
---
|
||||
|
||||
- A short introduction describing who you are and what you're looking for.
|
||||
- What projects have you enjoyed working on?
|
@ -0,0 +1,16 @@
|
||||
---
|
||||
id: how-to-apply
|
||||
title: How to Apply
|
||||
---
|
||||
|
||||
## Apply Directly
|
||||
|
||||
TODO
|
||||
|
||||
## Referrals
|
||||
|
||||
TODO
|
||||
|
||||
## Agencies/Portals
|
||||
|
||||
TODO
|
@ -0,0 +1,162 @@
|
||||
---
|
||||
id: interview-formats
|
||||
title: Interview Formats
|
||||
---
|
||||
|
||||
Interviews are a multi-stage process and each stage can consist of vastly different formats.
|
||||
|
||||
## Various formats
|
||||
|
||||
### Pop quiz
|
||||
|
||||
Pop quizzes are meant to be a quick and dirty way of weeding out extremely weak (or even non-technical) candidates. They are structured questions and have clear-cut answers which makes them possible to be administered by recruiters/non-technical folks. It is not a very common interview format these days.
|
||||
|
||||
Examples:
|
||||
|
||||
- What is 4 & 5 (in binary)? Answer: 4
|
||||
- What is the time complexity of bubble sort? Answer: O(n^2)
|
||||
|
||||
### Take home assignment
|
||||
|
||||
There has been numerous debates on whether asking algorithm questions are a good way of assessing individual abilities as they aren't exactly the most relevant skills needed for a job. Take home assignment is a format designed to address the shortcomings of the algorithm interview by getting candidates to work on larger projects which allow them to demonstrate software design skills.
|
||||
|
||||
However, this interview format takes up more time from both the candidates and the company and hence it is not as commonly seen in large companies where they have a high volume of candidates. This format is more common among startups and small companies.
|
||||
|
||||
Examples
|
||||
|
||||
- Build a flights listing app
|
||||
- Build a snake game
|
||||
|
||||
### Phone interview
|
||||
|
||||
Phone interviews are the most common format and every candidate will face this at least once while interviewing. You will be asked to speak with an interviewer either over a phone call or VoIP (Skype/Hangout). A question will be given to you and you will work on that question using an online collaborative editor (CoderPad/CodePen/Google Docs).
|
||||
|
||||
You are usually not allowed to execute the code even if the editor supports execution. So don't rely on that for verifying the correctness of your solution. Formats would differ slightly depending on the roles you are applying to. Many companies like to use [CoderPad](https://coderpad.io/) for collaborative code editing. CoderPad supports running of the program, so it is possible that you will be asked to fix your code such that it can be run. For front end interviews, many companies like to use [CodePen](https://codepen.io/), and it will be worth your time to familiarize yourself with the user interfaces of such web-based coding environments.
|
||||
|
||||
### Onsite
|
||||
|
||||
If you have made it to this stage, congratulations! This is usually the final stage before an offer decision. Candidates who made it to the onsite stage will be required to have an in-person interview at the office. If you are an overseas candidate, companies might even fly you in and pay for your accommodations!
|
||||
|
||||
The onsite stage usually consists of multiple rounds (coding, system design, behavioral) and is expected to last for a few hours. Since you are onsite, it is possible that you will be asked to do a whiteboard exercise with an interviewer, usually either solving an algorithm question or doing a system design question. It is also possible that you have to bring your own laptops and work on a project/solve a coding problem on the spot.
|
||||
|
||||
For onsite interviews at smaller (non-public) companies, most will allow (and prefer) that you use your own laptop. Hence it is important that you prepare your development environment in advance.
|
||||
|
||||
If the company provides lunch, you might also have a lunch session with an employee where you can find out more about the company culture.
|
||||
|
||||
## Formats of famous companies
|
||||
|
||||
### Airbnb
|
||||
|
||||
- Recruiter phone screen
|
||||
- Technical phone interview:
|
||||
- 1 or 2 x Algorithm/front end on CoderPad/CodePen
|
||||
- On-site (General):
|
||||
- 2 x Algorithm coding on CoderPad
|
||||
- 1 x System design/architecture
|
||||
- 1 x Past experience/project
|
||||
- 2 x Cross functional
|
||||
- On-site (Front End):
|
||||
- 2 x Front end coding on CodePen. Use any framework/library
|
||||
- 1 x General coding on your own laptop
|
||||
- 1 x Past experience/project
|
||||
- 2 x Cross functional
|
||||
- Tips:
|
||||
- All sessions involve coding on your own laptop. Prepare your development environment in advance
|
||||
- You are allowed to look up APIs if you need to
|
||||
- They seem to place high emphasis on compilable, runnable code in all their coding rounds
|
||||
- Cross functional interviews will involve getting Airbnb employees from any discipline to speak with you. These interviews are mostly non-technical but are extremely important to Airbnb because they place a high emphasis on cultural fit. Do look up the Airbnb section of the behavioral questions to know what sort of questions to expect
|
||||
|
||||
### Asana
|
||||
|
||||
- Recruiter phone screen
|
||||
- Technical phone interview
|
||||
- On-site (Product Engineer):
|
||||
- 3 x Algorithm and system design on whiteboard within the same session
|
||||
- 1 x Algorithm on laptop and system design. This session involves writing code on your own laptop to solve 3 well-defined algorithm problems in around 45 minutes after which an engineer will come in and review the code with you. You are not supposed to run the code while working on the problem
|
||||
- Tips:
|
||||
- No front end questions were asked
|
||||
- Asana places high emphasis on System Design and makes heavy use of the whiteboard. You do not necessarily have to write code for the algorithm question of the first three interviews
|
||||
- All 4 sessions involve algorithms and system design. One of the sessions will be conducted by an Engineering Manager
|
||||
- The last session will involve coding on your own laptop. Prepare your development environment in advance
|
||||
- Regardless of Product Engineer or Engineering Generalist position, their interview format and questions are similar
|
||||
|
||||
### Dropbox
|
||||
|
||||
- Recruiter phone screen
|
||||
- Technical phone interviews:
|
||||
- 2 x Algorithm/front end on CoderPad/CodePen
|
||||
- On-site (Front End):
|
||||
- 2 x Front end on CodePen. Only Vanilla JS or jQuery allowed
|
||||
- 1 x General coding on CoderPad
|
||||
- 1 x All around. Meet with an Engineering Manager and discussing past experiences and working style
|
||||
- Tips:
|
||||
- You can code on your own laptop and look up APIs
|
||||
- Dropbox recruiters are very nice and will give you helpful information on what kind of questions to expect for the upcoming sessions
|
||||
- One of the front end sessions involve coding up a pixel-perfect version of a real page on www.dropbox.com. You'll be given a spec of the desired page and you'll be asked to create a working version during the interview
|
||||
|
||||
### Facebook
|
||||
|
||||
- Recruiter phone screen
|
||||
- Technical phone interviews:
|
||||
- 1 or 2 x Algorithm/front end on Skype/CoderPad
|
||||
- On-site (Front End):
|
||||
- 2 x Technical coding interview on whiteboard (Ninja)
|
||||
- 1 x Behavioural (Jedi). Meet with an Engineering Manager and discussing past experiences and working style
|
||||
- 1 x Design/architecture on whiteboard (Pirate)
|
||||
- Tips:
|
||||
- You are only allowed to use the whiteboard (or wall). No laptops involved
|
||||
- For the Jedi round, you may be asked a technical question at the end of it. Front end candidates will be given a small HTML/CSS problem nearing the end of the session
|
||||
- For the Ninja rounds, you may be asked one to two questions depending on how fast you progress through the question
|
||||
|
||||
### Google
|
||||
|
||||
- Recruiter phone screen
|
||||
- Technical phone interview:
|
||||
- 1 or 2 x algorithm on Google Doc
|
||||
- On-site:
|
||||
- 1 or 2 x Front end on whiteboard. May be required to use Vanilla JS (or at the most, jQuery) depending on the question. (Front End only)
|
||||
- 2 to 4 x Algorithm on whiteboard
|
||||
- 1 x General Cognitive Ability, Leadership and "Googleyness".
|
||||
- Team matching
|
||||
- Speak with managers from different teams who are interested in your profile
|
||||
- Tips:
|
||||
- In rare cases, candidates may even be allowed to skip the phone interview round and advanced to on-site directly
|
||||
- For non-fresh grads, you only receive an offer if you are successfully matched with a team
|
||||
|
||||
### Lyft
|
||||
|
||||
- Recruiter phone screen
|
||||
- Technical phone interview:
|
||||
- 1 x Algorithm/Front end over JSFiddle
|
||||
- On-site (Front End):
|
||||
- 4 x Front end on Coderpad/your own laptop. Use any language/framework
|
||||
- 1 x Behavioral. Meet with an Engineering Manager and go through candidate's resume
|
||||
- Tips:
|
||||
- Can use whiteboard and/or laptop
|
||||
- For front end coding, I opted to use React and had to set up the projects on the spot using `create-react-app`
|
||||
|
||||
### Palantir
|
||||
|
||||
- Recruiter phone screen
|
||||
- Technical phone interview:
|
||||
- 1 x Algorithm over HackerRank CodePair and Skype
|
||||
- On-site (General):
|
||||
- 2 x Algorithm on whiteboard
|
||||
- 1 x Decomposition (system design) on whiteboard
|
||||
- On-site (Front End):
|
||||
- 1 x Front end on your own laptop. This session lasts about 1.5 hours. Use any library/framework
|
||||
- 1 x Decomposition (system design) on whiteboard
|
||||
- Tips:
|
||||
- I opted to use React and had to set up projects on the spot using `create-react-app`
|
||||
- You may be asked to meet with Engineering Managers after the technical sessions and it's not necessarily a good/bad thing
|
||||
|
||||
### WhatsApp
|
||||
|
||||
- Recruiter phone screen
|
||||
- Technical phone interview:
|
||||
- 2 x Algorithm over CoderPad
|
||||
- On-site (Web Client Developer):
|
||||
- 4 x Algorithm on whiteboard
|
||||
- Tips:
|
||||
- No front end questions were asked
|
||||
- 1 of the interviewers is an Engineering Manager
|
@ -0,0 +1,76 @@
|
||||
---
|
||||
id: interviewer-cheatsheet
|
||||
title: Cheatsheet (Interviewer)
|
||||
---
|
||||
|
||||
This is a straight-to-the-point, distilled list of technical interview Do's and Don'ts **for interviewers**, mainly for algorithmic interviews. Some of these may apply to only phone screens or whiteboard interviews, but most will apply to both. I revise this list before each of my interviews as an interviewer to remind myself of them and eventually internalized all of them to the point I do not have to rely on it anymore.
|
||||
|
||||
**If you are a candidate you probably do not need to know this section well. You may read this to get a better sense of what an interviewer is supposed to do during an interview.**
|
||||
|
||||
#### Legend
|
||||
|
||||
- ✅ = Do
|
||||
- ❌ = Don't
|
||||
- ⚠️ = Situational
|
||||
|
||||
### Before interview
|
||||
|
||||
| | Things |
|
||||
| --- | --- |
|
||||
| ✅ | Make sure your surroundings are well-lit. |
|
||||
| ✅ | Find a quiet environment with good Internet connection. |
|
||||
| ✅ | Ensure webcam and audio are working. Test that your VC app is working well. |
|
||||
| ✅ | Prepare two to three questions and be familiar with the different approaches for solving the questions. |
|
||||
| ✅ | Familiarize yourself with the coding environment (CoderPad/CodePen). Set up the coding shortcuts, turn on autocompletion, tab spacing, etc. |
|
||||
|
||||
### Introduction
|
||||
|
||||
| | Things |
|
||||
| --- | --- |
|
||||
| ✅ | Check if candidate wants to use the restroom or take a break. |
|
||||
| ✅ | Give an overview of the interview format (introduction, duration, programming languages available, 5 min at the end for Q&A). |
|
||||
| ✅ | Do a self-introduction and get the candidate to introduce themselves. |
|
||||
| ✅ | Explain to candidate that they do not have to finish all questions and you might interrupt them abruptly. |
|
||||
| ❌ | Allow the candidate to spend too long introducing themselves. |
|
||||
|
||||
### Upon delivering the question
|
||||
|
||||
| | Things |
|
||||
| --- | --- |
|
||||
| ✅ | Ask if the candidate has seen the question before. |
|
||||
| ✅ | Give a small example for the question and the desired output. |
|
||||
| ✅ | Get the candidate to talk through the solution first before diving into coding. |
|
||||
| ✅ | Provide hints where appropriate. |
|
||||
| ✅ | If candidate is still stuck after providing hints, provide the solution and move to coding so that you can get coding signals. |
|
||||
|
||||
### During coding
|
||||
|
||||
| | Things |
|
||||
| --- | --- |
|
||||
| ✅ | If whiteboard interview, stand alongside candidate but also giving them space, instead of being distant, e.g seated down. |
|
||||
| ✅ | Take note of all the positive and negative signals. |
|
||||
| ❌ | Check the time in an overly-obvious manner. |
|
||||
|
||||
### After coding
|
||||
|
||||
| | Things |
|
||||
| --- | --- |
|
||||
| ✅ | Ask for candidate to provide test cases and run through the code with them. |
|
||||
| ✅ | Point out edge cases candidate missed and ask the candidate to address them. |
|
||||
| ✅ | Take note of the duration TC spent on each question to include in the feedback. |
|
||||
| ✅ | Ask for time complexity and space analysis. |
|
||||
| ✅ | Preserve the code somewhere - take a picture or copy the code out. |
|
||||
| ✅ | Stop the candidate when there is 5 minutes left. e.g. ("I'll stop you here and let's go to the next section") |
|
||||
|
||||
### Wrap up
|
||||
|
||||
| | Things |
|
||||
| --- | --- |
|
||||
| ✅ | Allow candidate to ask questions and answer them to the best of your ability. |
|
||||
| ✅ | Thank the candidate and wish them all the best. |
|
||||
|
||||
### Post interview
|
||||
|
||||
| | Things |
|
||||
| --- | --------------------------------------------------------- |
|
||||
| ✅ | Write feedback as soon as possible to not forget details. |
|
@ -0,0 +1,16 @@
|
||||
---
|
||||
id: introduction
|
||||
title: Introduction
|
||||
---
|
||||
|
||||
## What is this?
|
||||
|
||||
The **Tech Interview Handbook** contains carefully curated content to help you ace your next technical interview with a focus on algorithms. While there are a ton of interview resources on the internet, the best ones are either not free, or they do not cover the complete interview process, usually only focusing on algorithms.
|
||||
|
||||
## Why do I want this?
|
||||
|
||||
This repository has **practical** content that covers all phases of a technical interview, from applying for a job to passing the interviews to offer negotiation. Technically competent candidates might still find the non-technical content helpful as well.
|
||||
|
||||
## Who is this for?
|
||||
|
||||
Whether you are a beginner to technical interviews or a seasoned engineer who have not been on the other side of the interviewing table in a while and want to get back into the game, the Tech Interview Handbook has got you covered.
|
@ -0,0 +1,61 @@
|
||||
---
|
||||
id: landscape
|
||||
title: Landscape
|
||||
---
|
||||
|
||||
import useBaseUrl from '@docusaurus/useBaseUrl';
|
||||
|
||||
Most of the content covered here will be specific to the Bay Area. Landscape differences due to geographical location are mentioned briefly [below](#geographical-location).
|
||||
|
||||
## Career prospects as a Software Engineer
|
||||
|
||||
### High demand
|
||||
|
||||
Almost every domain leverages on technology, hence Software Engineers are needed in almost every industry. Demand for engineers is higher than supply, leading to generally high-paying jobs. Moreover, the demand is continuously growing.
|
||||
|
||||
### Stable career
|
||||
|
||||
Computer Science is rapidly gaining popularity and engineering is a highly-regarded professional career. Unlike the creative industry, you do not have to be the top 1% of the industry to lead a comfortable life. An engineer fresh out of college working at a Silicon Valley company (both large companies and startups) can expect to receive a starting salary of more than USD 100,000 and it just gets better from there.
|
||||
|
||||
### Require lifelong learning
|
||||
|
||||
Technology industry is an extremely fast-moving one. Many technologies used today didn't even exist/were popular a decade ago; in 2009, mobile app development and blockchain were pretty much unheard of. Engineers constantly need to upgrade their skills to stay relevant to the demands of the job market. Engineering is a great career for passionate individuals who like to learn.
|
||||
|
||||
### Flexible
|
||||
|
||||
A software engineering job is perhaps the most flexible job that exists in terms of hours, location and environment. Physical location is usually not an issue and there are many tech companies that are fully remote. There's no formal attire to be worn and working hours are generally flexible. Your co-workers would stare at you weirdly if you came to work wearing a shirt and tie.
|
||||
|
||||
## Internships vs full-time
|
||||
|
||||
If you dream of working at a top-tier tech company one day, getting hired via an intern conversion is by far the easiest way to achieve that. Internship interviews are extremely short (usually just 2 rounds whereas interviews for full-time roles are usually 4-5 rounds). Internships allow you to work at a company over a short period of time (3 months or so) and helps in understanding the company and engineering culture better. Companies also tend to give higher return job offers to high performing interns as they have proven to be effective at the job and fits into the culture; hence hiring them is considered to be relatively low-risk.
|
||||
|
||||
Top tech companies pay a ridiculous amount for interns:
|
||||
|
||||
<div class="text--center">
|
||||
|
||||
<img src={useBaseUrl('/img/internship-salaries.jpg')} />
|
||||
|
||||
_Salaries of top tech internships in 2016 ([source](https://twitter.com/rodneyfolz/status/724787290824798209))_
|
||||
|
||||
</div>
|
||||
|
||||
## Company size
|
||||
|
||||
Companies have different focuses depending on the stage they are at and the types of work to be done can also be vastly different. In the earlier stages where product-market fit hasn't been found, companies would be rapidly iterating on products and features, whereas larger companies that have already found the right product will focus on scaling their infrastructure and growing their users. Liquid compensation is also lower at early-stage companies due to the equity not being worth any money, but there is the chance of earning a lot more if/when the company IPOs or gets acquired.
|
||||
|
||||
| | Early-stage Startup | Late-stage Startup | Large Company |
|
||||
| --- | --- | --- | --- |
|
||||
| Company Size | <100 | 100-1000 | >1000 |
|
||||
| Compensation | Base salary is a bit higher than big companies. Higher equity amount but its value is hard to judge as the company's valuation is unclear and stocks are not worth money yet. | Base salary is a bit higher than big companies. Company valuation is clearer and stocks have higher chance of being worth money. | Depends on the prestige of the company. Compensation is usually market standard or better. Stocks are worth money if company has gone public. |
|
||||
| Types of Work | Mainly product development. Engineers have to wear multiple hats - Front End, Back End, DevOps, Design, etc. | Product development and some infra. | Diverse roles and specialized work; dedicated people for each role. Infra work is more common. Also more opportunities for internal transfers. |
|
||||
| Career Ladders | Unstructured. No (or very vague) career levels. No formal mentorship nor training. | Somewhat structured. | Very structured. Well-defined career levels. |
|
||||
| Iteration Speed | Extremely fast. Struggling to find product market fit. | Moderate. Has found product market fit, trying to grow user base. | Stable product with wide user base. Have to roll out changes incrementally and run experiments. |
|
||||
|
||||
## Geographical location
|
||||
|
||||
| | US (Silicon Valley/NY) | Singapore |
|
||||
| --- | --- | --- |
|
||||
| Starting Pay | USD 100,000 | Monthly $4320 (Median), $5000 (75th percentile) |
|
||||
| Talent Access | Global talent, diverse nationalities and backgrounds | Usually regional, mostly Asians |
|
||||
| Types of Companies | HQ of large companies (Facebook, Amazon, Apple, Google, Microsoft, etc), Startups | Branch offices of large companies, Startups |
|
||||
| Types of Engineering Work | Depends on size of office/company | Both product and infra (building new programming languages, frameworks, and tools) |
|
@ -0,0 +1,14 @@
|
||||
---
|
||||
id: mock-interviews
|
||||
title: Mock Interviews
|
||||
---
|
||||
|
||||
Interviewing is a skill that you can get better at. The steps mentioned above can be rehearsed over and over again until you have fully internalized them and following those steps become second nature to you. A good way to practice is to find a friend to partner with and the both of you can take turns to interview each other.
|
||||
|
||||
A great resource for practicing mock coding interviews would be [interviewing.io](https://iio.sh/r/DMCa). interviewing.io provides free, anonymous practice technical interviews with Google and Facebook engineers, which can lead to real jobs and internships. By virtue of being anonymous during the interview, the inclusive interview process is de-biased and low risk. At the end of the interview, both interviewer and interviewees can provide feedback to each other for the purpose of improvement. Doing well in your mock interviews will unlock the jobs page and allow candidates to book interviews (also anonymously) with top companies like Uber, Lyft, Quora, Asana and more. For those who are totally new to technical interviews, you can even view [recorded interviews](https://interviewing.io/recordings) and see how phone interviews are like. Read more about them [here](https://techcrunch.com/2017/09/27/interviewing-io-hopes-to-close-the-engineer-diversity-gap-with-anonymous-interviews/).
|
||||
|
||||
I have used interviewing.io both as an interviewer and an interviewee and found the experience to be really great! [Aline Lerner](https://twitter.com/alinelernerLLC), the CEO and co-founder of interviewing.io and her team are passionate about revolutionizing the technical interview process and helping candidates to improve their skills at interviewing. She has also published a number of technical interview-related articles on the [interviewing.io blog](http://blog.interviewing.io/). interviewing.io is still in beta now but I recommend signing up as early as possible to increase the likelihood of getting an invite.
|
||||
|
||||
Another platform that allows you to practice coding interviews is [Pramp](https://pramp.com/). Where interviewing.io matches potential job seekers with seasoned technical interviewers, Pramp takes a different approach. Pramp pairs you up with another peer who is also a job seeker and both of you take turns to assume the role of interviewer and interviewee. Pramp also prepares questions for you, along with suggested solutions and prompts to guide the interviewee.
|
||||
|
||||
Personally, I am not that fond of Pramp's approach because if I were to interview someone, I would rather choose a question I am familiar with. Also, many users of the platform do not have the experience of being interviewers and that can result in a horrible interview experience. There was once where my matched peer, as the interviewer, did not have the right understanding of the question and attempted to lead me down the wrong path of solving the question. However, this is more of a problem of the candidate than the platform though.
|
@ -0,0 +1,26 @@
|
||||
---
|
||||
id: picking-a-language
|
||||
title: Picking a Language
|
||||
---
|
||||
|
||||
Before anything else, you need to pick a programming language to do your interviews in. Most companies will let you code in any language you want, the only exception I know being Google, where they only allow candidates to pick from Java, C++, JavaScript or Python for their algorithmic coding interviews.
|
||||
|
||||
## Some languages are more suited for interviews
|
||||
|
||||
There are some languages which are more suitable than others for coding interviews and some languages you absolutely want to avoid. From my experience as an interviewer, most candidates pick Python or Java. Other commonly seen languages include JavaScript, Ruby and C++. I would absolutely avoid lower level languages like C or Go, simply because they lack many standard library functions and data structures and some may require manual memory management.
|
||||
|
||||
Personally, Python is my de facto choice for algorithm coding interviews because it is succinct and has a pretty huge library of functions and data structures available. One of my top reasons for recommending Python is that it uses consistent APIs that operate on different data structures, such as `len()`, `for ... in ...` and slicing notation on sequences (strings/lists/tuples). Getting the last element in a sequence is `arr[-1]` and reversing it is simply `arr[::-1]`. You can achieve a lot with minimal syntax in Python.
|
||||
|
||||
Java is a decent choice too but having to constantly declare types in your code means extra keystrokes which results in slower coding/typing speed. This issue will be more apparent when you have to write on a whiteboard during on-site interviews. The reasons for choosing/not choosing C++ are similar to Java. Ultimately, Python, Java and C++ are decent choices of languages.
|
||||
|
||||
## Use a language you are familiar with
|
||||
|
||||
Most of the time, it is recommended that you use a language that you are extremely familiar with rather than picking up a new language just for doing interviews because the company uses that language heavily or just because you want to show that you are trendy.
|
||||
|
||||
If you are under time constraints, picking up a new language just for interviewing is hardly a good idea. Languages take time to master and if you are already spending most of your time and effort on mastering algorithms, there is barely spare effort left for mastering a new language. If you are familiar with using one of the mainstream languages, there isn't a strong reason to learn a new language just for interviewing.
|
||||
|
||||
If you have been using Java at work for a while now and do not have time to be comfortably familiar with another language, I would recommend just sticking to Java instead of picking up Python from scratch just for the sake of interviews. Doing so, you can avoid having to context switch between languages during work vs interviews. Most of the time, the bottleneck is in the thinking and not the writing. It takes some getting used to before one becomes fluent in a language and be able to wield it with ease.
|
||||
|
||||
## The exception to the norm
|
||||
|
||||
One exception to the convention of allowing you to "pick any programming language you want" is when you are interviewing for a domain-specific position, such as Front End/iOS/Android Engineer roles, in which you would need to be familiar with coding in JavaScript, Objective-C/Swift and Java respectively. If you need to use a data structure that the language does not support, such as a Queue or Heap in JavaScript, perhaps try asking the interviewer whether you can assume that you have a data structure that implements certain methods with specified time complexities. If the implementation of that data structure is not crucial to solving the problem, the interviewer will usually allow this. In reality, being aware of existing data structures and selecting the appropriate ones to tackle the problem at hand is more important than knowing the intricate implementation details.
|
@ -1,5 +1,7 @@
|
||||
Psychological Tricks
|
||||
==
|
||||
---
|
||||
id: psychological-tricks
|
||||
title: Psychological Tricks
|
||||
---
|
||||
|
||||
Here are some psychological tricks that will help you ace a job interview.
|
||||
|
@ -0,0 +1,76 @@
|
||||
---
|
||||
id: understanding-compensation
|
||||
title: Understanding Compensation
|
||||
---
|
||||
|
||||
Compensation is a huge factor when it comes to deciding between job offers. This section gives you a breakdown of the common components of compensation in the tech industry.
|
||||
|
||||
In most companies, your compensation will consist of base salary, a performance bonus and equity/stocks. For compensation data, check out [Levels.fyi](https://www.levels.fyi).
|
||||
|
||||
### Base salary
|
||||
|
||||
Base salary is a fixed amount of salary you get for showing up at work and is unaffected by how well the company is performing or the industry is doing. It is the only non-variable component of your compensation.
|
||||
|
||||
Fresh graduates in the Bay Area can usually expect to get a base salary of above USD 100,000 (before taxes). The salary for fresh graduates at Facebook/Google is known to be in the USD 100,000 - 150,000 range.
|
||||
|
||||
Startups usually offer a bit higher for fresh graduate (USD 120,000 - 130,000) to make up for the lack of liquidity of the equity grant (not yet real cash).
|
||||
|
||||
Base salary doesn't increase linearly as you become more senior; it will plateau off eventually. As employees become increasingly senior within the company, the higher the proportion of their compensation comes from company-dependent factors such as bonus and equity. This is because senior employees are expected to influence the people around them and drive the company forward. A senior employee's performance will be based on how well the company does as a whole; the individual factor will not be as much.
|
||||
|
||||
There are some exceptions to the system. Companies like Netflix pay top in the industry (sometimes even more than Facebook/Google) and give employees the option to receive their entire compensation as base salary, that is, to convert the equity component into their base. For the risk-adverse, this is a great choice.
|
||||
|
||||
### Bonus
|
||||
|
||||
Bonuses are usually paid on a semi-annual basis and are typically dependent on a few factors - level of seniority, individual performance in that time period, company performance in that time period.
|
||||
|
||||
- **Level of seniority** - This is usually a multiplier of the base salary, and the multiplier increases as the employee moves up the ranks
|
||||
- **Individual performance** - This is a multiplier of how well an employee performed in that time period. E.g. meeting expectations results in a 100% multiplier and exceeding expectations results in a >100% multiplier. Companies like Facebook and Apple reward their top performers handsomely, and the multiplier can go up to 300% for the extremely high-performing employees
|
||||
- **Company performance** - How well the company is doing. This multiplier will be the same for all employees
|
||||
|
||||
#### Examples
|
||||
|
||||
- Bob is a Software Engineer fresh out of college. His base salary is 100,000, is a fresh grad (seniority multiplier: 10%), crushed expectations for the half (individual performance multiplier: 200%) and his company did pretty well (company performance multiplier: 120%). For that half, his bonus will be as follows:
|
||||
|
||||
- **Bonus:** 100,000 x 50% (half a year) x 10% (seniority) x 200% (individual performance) x 120% (company performance) = 12000
|
||||
|
||||
- Alice is an Engineering Manager with 10 years of professional experience. Her base salary is 220,000, is an experienced engineering manager (seniority multiplier: 20%), exceeded expectations for the half (individual performance multiplier: 150%) and her company did pretty awesome (company performance multiplier: 130%). For that half, her bonus will be as follows:
|
||||
|
||||
- **Bonus:** 220,000 x 50% (half a year) x 20% (seniority) x 150% (individual performance) x 130% (company performance) = 42900
|
||||
|
||||
Hence the amount of bonus you receive can be highly variable and senior employees get a higher proportion of their compensation from bonuses.
|
||||
|
||||
### Equity/Stocks
|
||||
|
||||
Equity is what differentiates a tech job from a non-tech one. Equity means a share of the company; this signifies ownership and motivates employees to work in the best interests of the company. They can be a significant portion of one's compensation, sometimes even more than the base salary, especially for senior employees.
|
||||
|
||||
Equity usually vests (becomes available to you) over a period of time (typically 4 years) and can vest equally every month/quarter/year. A vesting cliff means the minimum period of time before your vesting begins. For example, if you are granted 4,800 shares over a 4 year schedule with a 1 year cliff, and monthly vesting, you will get 1,200 shares at the end of your first year and 100 shares every month thereafter for the subsequent 3 years.
|
||||
|
||||
Until the company goes public or gets acquired, the equity is not worth anything. Be mindful of what you are getting yourself into!
|
||||
|
||||
Not all equity is treated equally. Depending on the company you join and which stage that company is at, you may receive one of the following types: stock options or stock grants.
|
||||
|
||||
#### Stock options
|
||||
|
||||
Stock options are typically given by mid-stage companies. Stock options are different from stocks, which represents the immediate ownership of a company! Stock options are the **option/right** to purchase stocks at a given strike price, hence it's not free. However, the cost of each stock is usually quite low and fixed at a strike price, which is equal to the fair market value of the stock when it was granted to you. You are guaranteed to be able to purchase the stock at that price regardless of future increases.
|
||||
|
||||
When you leave a company, there is an exercise window (deadline given for you to exercise your options before they are gone), so it is important to have enough liquid cash to purchase them when planning a departure.
|
||||
|
||||
#### Stock grants
|
||||
|
||||
A stock grant is commonly referred to as a Restricted Stock Unit (RSU) and it means you possess the stock immediately. If the company is public, you can sell them during defined trading windows.
|
||||
|
||||
More reading on the topic can be done [here](https://gist.github.com/yossorion/4965df74fd6da6cdc280ec57e83a202d).
|
||||
|
||||
### Signing bonus
|
||||
|
||||
This is a one-time lump sum that is paid to you when you join a company. This amount is typically in the range of USD 10,000 to USD 20,000 but can even go up to USD 50,000 (Google) and USD 100,000 (Facebook).
|
||||
|
||||
There can be conditions attached to signing bonuses, such as having to return a pro-rated amount if an employee leaves before the one-year mark. Make sure you are aware of them before you sign the offer.
|
||||
|
||||
### Misc bonuses/perks
|
||||
|
||||
While these perks are not exactly cash, they can help you save money which is almost equivalent to getting compensated more.
|
||||
|
||||
- Free meals - Food is not exactly cheap in the Bay Area and having some meals provided on weekdays can result in saving few thousand dollars a year
|
||||
- Relocation bonus - Helpful if you are moving from abroad, and this can partially offset costs due to relocating
|
||||
- Shuttle service - Public transportation in the Bay Area is not that great and the most common form of commute is driving. Being able to take a shuttle service helps in saving money on gas, transport, and freeing up your mind to do other things during the commute
|
@ -1,94 +1,5 @@
|
||||
Design Questions
|
||||
==
|
||||
# System Design
|
||||
|
||||
## Guides
|
||||
## Specific topics
|
||||
|
||||
- https://github.com/donnemartin/system-design-primer
|
||||
- https://github.com/checkcheckzz/system-design-interview
|
||||
- https://github.com/shashank88/system_design
|
||||
- https://gist.github.com/vasanthk/485d1c25737e8e72759f
|
||||
- http://www.puncsky.com/blog/2016/02/14/crack-the-system-design-interview/
|
||||
- https://www.palantir.com/2011/10/how-to-rock-a-systems-design-interview/
|
||||
- http://blog.gainlo.co/index.php/2017/04/13/system-design-interviews-part-ii-complete-guide-google-interview-preparation/
|
||||
|
||||
## Flow
|
||||
|
||||
#### A. Understand the problem and scope
|
||||
|
||||
- Define the use cases, with interviewer's help.
|
||||
- Suggest additional features.
|
||||
- Remove items that interviewer deems out of scope.
|
||||
- Assume high availability is required, add as a use case.
|
||||
|
||||
#### B. Think about constraints
|
||||
|
||||
- Ask how many requests per month.
|
||||
- Ask how many requests per second (they may volunteer it or make you do the math).
|
||||
- Estimate reads vs. writes percentage.
|
||||
- Keep 80/20 rule in mind when estimating.
|
||||
- How much data written per second.
|
||||
- Total storage required over 5 years.
|
||||
- How much data reads per second.
|
||||
|
||||
#### C. Abstract design
|
||||
|
||||
- Layers (service, data, caching).
|
||||
- Infrastructure: load balancing, messaging.
|
||||
- Rough overview of any key algorithm that drives the service.
|
||||
- Consider bottlenecks and determine solutions.
|
||||
|
||||
Source: https://github.com/jwasham/coding-interview-university#system-design-scalability-data-handling
|
||||
|
||||
## Grading Rubrics
|
||||
|
||||
- Problem Solving - How systematic is your approach to solving the problem step-by-step? Break down a problem into its core components.
|
||||
- Communication - How well do you explain your idea and communicate it with others?
|
||||
- Evaluation - How do you evaluate your system? Are you aware of the trade-offs made? How can you optimize it?
|
||||
- Estimation - How fast does your system need to be? How much space does it need? How much load will it experience?
|
||||
|
||||
## Specific Topics
|
||||
|
||||
- URL Shortener
|
||||
- http://stackoverflow.com/questions/742013/how-to-code-a-url-shortener
|
||||
- http://blog.gainlo.co/index.php/2016/03/08/system-design-interview-question-create-tinyurl-system/
|
||||
- https://www.interviewcake.com/question/python/url-shortener
|
||||
- Collaborative Editor
|
||||
- http://blog.gainlo.co/index.php/2016/03/22/system-design-interview-question-how-to-design-google-docs/
|
||||
- Photo Sharing App
|
||||
- http://blog.gainlo.co/index.php/2016/03/01/system-design-interview-question-create-a-photo-sharing-app/
|
||||
- Social Network Feed
|
||||
- http://blog.gainlo.co/index.php/2016/02/17/system-design-interview-question-how-to-design-twitter-part-1/
|
||||
- http://blog.gainlo.co/index.php/2016/02/24/system-design-interview-question-how-to-design-twitter-part-2/
|
||||
- http://blog.gainlo.co/index.php/2016/03/29/design-news-feed-system-part-1-system-design-interview-questions/
|
||||
- Trending Algorithm
|
||||
- http://blog.gainlo.co/index.php/2016/05/03/how-to-design-a-trending-algorithm-for-twitter/
|
||||
- Facebook Chat
|
||||
- http://blog.gainlo.co/index.php/2016/04/19/design-facebook-chat-function/
|
||||
- Key Value Store
|
||||
- http://blog.gainlo.co/index.php/2016/06/14/design-a-key-value-store-part-i/
|
||||
- http://blog.gainlo.co/index.php/2016/06/21/design-key-value-store-part-ii/
|
||||
- Recommendation System
|
||||
- http://blog.gainlo.co/index.php/2016/05/24/design-a-recommendation-system/
|
||||
- Cache System
|
||||
- http://blog.gainlo.co/index.php/2016/05/17/design-a-cache-system/
|
||||
- E-commerce Website
|
||||
- http://blog.gainlo.co/index.php/2016/08/22/design-ecommerce-website-part/
|
||||
- http://blog.gainlo.co/index.php/2016/08/28/design-ecommerce-website-part-ii/
|
||||
- Web Crawler
|
||||
- http://blog.gainlo.co/index.php/2016/06/29/build-web-crawler/
|
||||
- http://www.makeuseof.com/tag/how-do-search-engines-work-makeuseof-explains/
|
||||
- https://www.quora.com/How-can-I-build-a-web-crawler-from-scratch/answer/Chris-Heller
|
||||
- YouTube
|
||||
- http://blog.gainlo.co/index.php/2016/10/22/design-youtube-part/
|
||||
- http://blog.gainlo.co/index.php/2016/11/04/design-youtube-part-ii/
|
||||
- Hit Counter
|
||||
- http://blog.gainlo.co/index.php/2016/09/12/dropbox-interview-design-hit-counter/
|
||||
- Facebook Graph Search
|
||||
- Design [Lyft Line](https://www.lyft.com/line).
|
||||
- Design a promo code system (with same promo code, randomly generated promo code, and promo code with conditions).
|
||||
- Model a university.
|
||||
- How would you implement Pacman?
|
||||
- Sketch out an implementation of Asteroids.
|
||||
- Implement a spell checker.
|
||||
- Design the rubik cube.
|
||||
- Design a high-level interface to be used for card games (e.g. poker, blackjack etc).
|
||||
The contents have been moved to a different [location](../experimental/design#specific-topics).
|
||||
|
@ -0,0 +1,94 @@
|
||||
# Design Questions
|
||||
|
||||
## Guides
|
||||
|
||||
- [Grokking the System Design Interview](https://www.educative.io/collection/5668639101419520/5649050225344512)
|
||||
- https://github.com/donnemartin/system-design-primer
|
||||
- https://github.com/checkcheckzz/system-design-interview
|
||||
- https://github.com/shashank88/system_design
|
||||
- https://gist.github.com/vasanthk/485d1c25737e8e72759f
|
||||
- http://www.puncsky.com/blog/2016/02/14/crack-the-system-design-interview/
|
||||
- https://www.palantir.com/2011/10/how-to-rock-a-systems-design-interview/
|
||||
- http://blog.gainlo.co/index.php/2017/04/13/system-design-interviews-part-ii-complete-guide-google-interview-preparation/
|
||||
|
||||
## Flow
|
||||
|
||||
#### A. Understand the problem and scope
|
||||
|
||||
- Define the use cases, with interviewer's help.
|
||||
- Suggest additional features.
|
||||
- Remove items that interviewer deems out of scope.
|
||||
- Assume high availability is required, add as a use case.
|
||||
|
||||
#### B. Think about constraints
|
||||
|
||||
- Ask how many requests per month.
|
||||
- Ask how many requests per second (they may volunteer it or make you do the math).
|
||||
- Estimate reads vs. writes percentage.
|
||||
- Keep 80/20 rule in mind when estimating.
|
||||
- How much data written per second.
|
||||
- Total storage required over 5 years.
|
||||
- How much data reads per second.
|
||||
|
||||
#### C. Abstract design
|
||||
|
||||
- Layers (service, data, caching).
|
||||
- Infrastructure: load balancing, messaging.
|
||||
- Rough overview of any key algorithm that drives the service.
|
||||
- Consider bottlenecks and determine solutions.
|
||||
|
||||
Source: https://github.com/jwasham/coding-interview-university#system-design-scalability-data-handling
|
||||
|
||||
## Grading Rubrics
|
||||
|
||||
- Problem Solving - How systematic is your approach to solving the problem step-by-step? Break down a problem into its core components.
|
||||
- Communication - How well do you explain your idea and communicate it with others?
|
||||
- Evaluation - How do you evaluate your system? Are you aware of the trade-offs made? How can you optimize it?
|
||||
- Estimation - How fast does your system need to be? How much space does it need? How much load will it experience?
|
||||
|
||||
## Specific Topics
|
||||
|
||||
- URL Shortener
|
||||
- http://stackoverflow.com/questions/742013/how-to-code-a-url-shortener
|
||||
- http://blog.gainlo.co/index.php/2016/03/08/system-design-interview-question-create-tinyurl-system/
|
||||
- https://www.interviewcake.com/question/python/url-shortener
|
||||
- Collaborative Editor
|
||||
- http://blog.gainlo.co/index.php/2016/03/22/system-design-interview-question-how-to-design-google-docs/
|
||||
- Photo Sharing App
|
||||
- http://blog.gainlo.co/index.php/2016/03/01/system-design-interview-question-create-a-photo-sharing-app/
|
||||
- Social Network Feed
|
||||
- http://blog.gainlo.co/index.php/2016/02/17/system-design-interview-question-how-to-design-twitter-part-1/
|
||||
- http://blog.gainlo.co/index.php/2016/02/24/system-design-interview-question-how-to-design-twitter-part-2/
|
||||
- http://blog.gainlo.co/index.php/2016/03/29/design-news-feed-system-part-1-system-design-interview-questions/
|
||||
- Trending Algorithm
|
||||
- http://blog.gainlo.co/index.php/2016/05/03/how-to-design-a-trending-algorithm-for-twitter/
|
||||
- Facebook Chat
|
||||
- http://blog.gainlo.co/index.php/2016/04/19/design-facebook-chat-function/
|
||||
- Key Value Store
|
||||
- http://blog.gainlo.co/index.php/2016/06/14/design-a-key-value-store-part-i/
|
||||
- http://blog.gainlo.co/index.php/2016/06/21/design-key-value-store-part-ii/
|
||||
- Recommendation System
|
||||
- http://blog.gainlo.co/index.php/2016/05/24/design-a-recommendation-system/
|
||||
- Cache System
|
||||
- http://blog.gainlo.co/index.php/2016/05/17/design-a-cache-system/
|
||||
- E-commerce Website
|
||||
- http://blog.gainlo.co/index.php/2016/08/22/design-ecommerce-website-part/
|
||||
- http://blog.gainlo.co/index.php/2016/08/28/design-ecommerce-website-part-ii/
|
||||
- Web Crawler
|
||||
- http://blog.gainlo.co/index.php/2016/06/29/build-web-crawler/
|
||||
- http://www.makeuseof.com/tag/how-do-search-engines-work-makeuseof-explains/
|
||||
- https://www.quora.com/How-can-I-build-a-web-crawler-from-scratch/answer/Chris-Heller
|
||||
- YouTube
|
||||
- http://blog.gainlo.co/index.php/2016/10/22/design-youtube-part/
|
||||
- http://blog.gainlo.co/index.php/2016/11/04/design-youtube-part-ii/
|
||||
- Hit Counter
|
||||
- http://blog.gainlo.co/index.php/2016/09/12/dropbox-interview-design-hit-counter/
|
||||
- Facebook Graph Search
|
||||
- Design [Lyft Line](https://www.lyft.com/line).
|
||||
- Design a promo code system (with same promo code, randomly generated promo code, and promo code with conditions).
|
||||
- Model a university.
|
||||
- How would you implement Pacman?
|
||||
- Sketch out an implementation of Asteroids.
|
||||
- Implement a spell checker.
|
||||
- Design the rubik cube.
|
||||
- Design a high-level interface to be used for card games (e.g. poker, blackjack etc).
|
@ -1,5 +1,4 @@
|
||||
Collaborative Document Editor
|
||||
==
|
||||
# Collaborative Document Editor
|
||||
|
||||
## Variants
|
||||
|
@ -1,5 +1,4 @@
|
||||
Search Engine
|
||||
==
|
||||
# Search Engine
|
||||
|
||||
###### References
|
||||
|
@ -1,5 +1,4 @@
|
||||
Databases
|
||||
==
|
||||
# Databases
|
||||
|
||||
## General
|
||||
|
@ -1,5 +1,4 @@
|
||||
Networking
|
||||
==
|
||||
# Networking
|
||||
|
||||
- Given an IPv4 IP address p and an integer n, return a list of CIDR strings that most succinctly represents the range of IP addresses from p to (p + n).
|
||||
- Describe what happens when you enter a url in the web browser.
|
@ -1,5 +1,4 @@
|
||||
Software Engineering
|
||||
==
|
||||
# Software Engineering
|
||||
|
||||
## What is the difference between an interface and abstract class?
|
||||
|
@ -0,0 +1,3 @@
|
||||
# Front-end Job Interview Questions
|
||||
|
||||
Front-end Job Interview Questions have been migrated [here](https://github.com/yangshun/front-end-interview-handbook).
|
@ -1,18 +1,18 @@
|
||||
function binarySearch(arr, target) {
|
||||
let left = 0;
|
||||
let right = arr.length - 1;
|
||||
while (left <= right) {
|
||||
const mid = left + Math.floor((right - left) / 2);
|
||||
if (arr[mid] === target) {
|
||||
return mid;
|
||||
}
|
||||
if (arr[mid] < target) {
|
||||
left = mid + 1;
|
||||
} else {
|
||||
right = mid - 1;
|
||||
}
|
||||
let left = 0;
|
||||
let right = arr.length - 1;
|
||||
while (left <= right) {
|
||||
const mid = left + Math.floor((right - left) / 2);
|
||||
if (arr[mid] === target) {
|
||||
return mid;
|
||||
}
|
||||
return -1;
|
||||
if (arr[mid] < target) {
|
||||
left = mid + 1;
|
||||
} else {
|
||||
right = mid - 1;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
console.log(binarySearch([1, 2, 3, 10], 1) === 0);
|
@ -0,0 +1,43 @@
|
||||
function deepEqual(val1, val2) {
|
||||
if (typeof val1 !== typeof val2) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Array comparison.
|
||||
if (Array.isArray(val1) && Array.isArray(val2)) {
|
||||
if (val1.length !== val2.length) {
|
||||
return false;
|
||||
}
|
||||
for (let i = 0; i < val1.length; i++) {
|
||||
if (!deepEqual(val1[i], val2[i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Object comparison.
|
||||
if (
|
||||
typeof val1 === 'object' &&
|
||||
typeof val2 === 'object' &&
|
||||
val1 !== null &&
|
||||
val2 !== null
|
||||
) {
|
||||
const keys1 = Object.keys(val1),
|
||||
keys2 = Object.keys(val2);
|
||||
if (keys1.length !== keys2.length) {
|
||||
return false;
|
||||
}
|
||||
for (let i = 0; i < keys1.length; i++) {
|
||||
if (!deepEqual(val1[keys1[i]], val2[keys2[i]])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Primitive comparison.
|
||||
return val1 === val2;
|
||||
}
|
||||
|
||||
module.exports = deepEqual;
|
@ -0,0 +1,35 @@
|
||||
function graphTopoSort(numberNodes, edges) {
|
||||
const nodes = new Map();
|
||||
const order = [];
|
||||
const queue = [];
|
||||
for (let i = 0; i < numberNodes; i++) {
|
||||
nodes.set(i, {in: 0, out: new Set()});
|
||||
}
|
||||
|
||||
edges.forEach(edge => {
|
||||
const [node_id, pre_id] = edge;
|
||||
nodes.get(node_id).in += 1;
|
||||
nodes.get(pre_id).out.add(node_id);
|
||||
});
|
||||
|
||||
for (let [node_id, value] of nodes.entries()) {
|
||||
if (value.in === 0) {
|
||||
queue.push(node_id);
|
||||
}
|
||||
}
|
||||
|
||||
while (queue.length) {
|
||||
const node_id = queue.shift();
|
||||
for (let outgoing_id of nodes.get(node_id).out) {
|
||||
nodes.get(outgoing_id).in -= 1;
|
||||
if (nodes.get(outgoing_id).in === 0) {
|
||||
queue.push(outgoing_id);
|
||||
}
|
||||
}
|
||||
order.push(node_id);
|
||||
}
|
||||
|
||||
return order.length == numberNodes ? order : [];
|
||||
}
|
||||
|
||||
console.log(graphTopoSort(3, [[0, 1], [0, 2]]));
|
@ -0,0 +1,21 @@
|
||||
// Does not handle negative numbers.
|
||||
function intToBin(number) {
|
||||
if (number === 0) {
|
||||
return '0';
|
||||
}
|
||||
let res = '';
|
||||
while (number > 0) {
|
||||
res = String(number % 2) + res;
|
||||
number = parseInt(number / 2, 10);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
console.log(intToBin(0) === (0).toString(2) && (0).toString(2) === '0');
|
||||
console.log(intToBin(1) === (1).toString(2) && (1).toString(2) === '1');
|
||||
console.log(intToBin(2) === (2).toString(2) && (2).toString(2) === '10');
|
||||
console.log(intToBin(3) === (3).toString(2) && (3).toString(2) === '11');
|
||||
console.log(intToBin(5) === (5).toString(2) && (5).toString(2) === '101');
|
||||
console.log(
|
||||
intToBin(99) === (99).toString(2) && (99).toString(2) === '1100011',
|
||||
);
|
@ -1,6 +1,6 @@
|
||||
// Interval: [start, end].
|
||||
function intervalsIntersect(a, b) {
|
||||
return a[0] < b[1] && b[0] < a[1];
|
||||
return a[0] < b[1] && b[0] < a[1];
|
||||
}
|
||||
|
||||
console.log(intervalsIntersect([1, 2], [3, 4]) === false);
|
@ -1,7 +1,7 @@
|
||||
// Interval: [start, end].
|
||||
// Merges two overlapping intervals into one.
|
||||
function intervalsMerge(a, b) {
|
||||
return [Math.min(a[0], b[0]), Math.max(a[1], b[1])];
|
||||
return [Math.min(a[0], b[0]), Math.max(a[1], b[1])];
|
||||
}
|
||||
|
||||
const deepEqual = require('./deepEqual');
|
@ -1,14 +1,14 @@
|
||||
function isSubsequence(s, t) {
|
||||
if (s.length > t.length) {
|
||||
return false;
|
||||
if (s.length > t.length) {
|
||||
return false;
|
||||
}
|
||||
let matchedLength = 0;
|
||||
for (let i = 0; i < t.length; i++) {
|
||||
if (matchedLength < s.length && s[matchedLength] === t[i]) {
|
||||
matchedLength += 1;
|
||||
}
|
||||
let matchedLength = 0;
|
||||
for (let i = 0; i < t.length; i++) {
|
||||
if (matchedLength < s.length && s[matchedLength] === t[i]) {
|
||||
matchedLength += 1;
|
||||
}
|
||||
}
|
||||
return matchedLength === s.length;
|
||||
}
|
||||
return matchedLength === s.length;
|
||||
}
|
||||
|
||||
console.log(isSubsequence('abc', 'abcde') === true);
|
@ -0,0 +1,30 @@
|
||||
function traverse(matrix) {
|
||||
const DIRECTIONS = [[0, 1], [0, -1], [1, 0], [-1, 0]];
|
||||
const rows = matrix.length;
|
||||
const cols = matrix[0].length;
|
||||
const visited = matrix.map(row => Array(row.length).fill(false));
|
||||
function dfs(i, j) {
|
||||
if (visited[i][j]) {
|
||||
return;
|
||||
}
|
||||
visited[i][j] = true;
|
||||
DIRECTIONS.forEach(dir => {
|
||||
const row = i + dir[0],
|
||||
col = j + dir[1];
|
||||
// Boundary check.
|
||||
if (row < 0 || row >= rows || col < 0 || col >= cols) {
|
||||
return;
|
||||
}
|
||||
// Valid neighbor check.
|
||||
if (matrix[row][col] !== 1) {
|
||||
return;
|
||||
}
|
||||
dfs(row, col);
|
||||
});
|
||||
}
|
||||
for (let i = 0; i < rows; i++) {
|
||||
for (let j = 0; j < cols; j++) {
|
||||
dfs(i, j);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
function mergeSort(arr) {
|
||||
if (arr.length < 2) {
|
||||
// Arrays of length 0 or 1 are sorted by definition.
|
||||
return arr;
|
||||
}
|
||||
|
||||
const left = arr.slice(0, Math.floor(arr.length / 2));
|
||||
const right = arr.slice(Math.floor(arr.length / 2), Math.floor(arr.length));
|
||||
|
||||
return merge(mergeSort(left), mergeSort(right));
|
||||
}
|
||||
|
||||
function merge(arr1, arr2) {
|
||||
const merged = [];
|
||||
let i = 0,
|
||||
j = 0;
|
||||
|
||||
while (i < arr1.length && j < arr2.length) {
|
||||
if (arr1[i] <= arr2[j]) {
|
||||
merged.push(arr1[i]);
|
||||
i++;
|
||||
} else if (arr2[j] < arr1[i]) {
|
||||
merged.push(arr2[j]);
|
||||
j++;
|
||||
}
|
||||
}
|
||||
|
||||
merged.push(...arr1.slice(i), ...arr2.slice(j));
|
||||
return merged;
|
||||
}
|
||||
|
||||
const deepEqual = require('./deepEqual');
|
||||
|
||||
console.log(deepEqual(mergeSort([]), []));
|
||||
console.log(deepEqual(mergeSort([1]), [1]));
|
||||
console.log(deepEqual(mergeSort([2, 1]), [1, 2]));
|
||||
console.log(deepEqual(mergeSort([7, 2, 4, 3, 1, 2]), [1, 2, 2, 3, 4, 7]));
|
||||
console.log(deepEqual(mergeSort([1, 2, 3, 4, 5, 0]), [0, 1, 2, 3, 4, 5]));
|
||||
console.log(
|
||||
deepEqual(mergeSort([10, 9, 8, 7, 6, 5, 4, 3, 2, 1]), [
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
4,
|
||||
5,
|
||||
6,
|
||||
7,
|
||||
8,
|
||||
9,
|
||||
10,
|
||||
]),
|
||||
);
|
||||
console.log(
|
||||
deepEqual(mergeSort([98322, 3242, 876, -234, 34, 12331]), [
|
||||
-234,
|
||||
34,
|
||||
876,
|
||||
3242,
|
||||
12331,
|
||||
98322,
|
||||
]),
|
||||
);
|
@ -0,0 +1,13 @@
|
||||
function treeEqual(node1, node2) {
|
||||
if (!node1 && !node2) {
|
||||
return true;
|
||||
}
|
||||
if (!node1 || !node2) {
|
||||
return false;
|
||||
}
|
||||
return (
|
||||
node1.val == node2.val &&
|
||||
treeEqual(node1.left, node2.left) &&
|
||||
treeEqual(node1.right, node2.right)
|
||||
);
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
function treeMirror(node) {
|
||||
if (!node) {
|
||||
return;
|
||||
}
|
||||
let temp = node.left;
|
||||
node.left = node.right;
|
||||
node.right = temp;
|
||||
treeMirror(node.left);
|
||||
treeMirror(node.right);
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
def graph_dfs(matrix):
|
||||
rows, cols = len(matrix), len(matrix[0])
|
||||
visited = set()
|
||||
directions = ((0, 1), (0, -1), (1, 0), (-1, 0))
|
||||
def dfs(i, j):
|
||||
if (i, j) in visited:
|
||||
return
|
||||
visited.add((i, j))
|
||||
# Traverse neighbors.
|
||||
for direction in directions:
|
||||
next_i, next_j = i + direction[0], j + direction[1]
|
||||
if 0 <= next_i < rows and 0 <= next_j < cols: # Check boundary.
|
||||
# Add any other checking here ^
|
||||
dfs(next_i, next_j)
|
||||
|
||||
for i in range(rows):
|
||||
for j in range(cols):
|
||||
dfs(i, j)
|
||||
|
||||
# Follow up:
|
||||
# 1) Diagonal cells are considered neighbors
|
||||
# 2) View the matrix like Earth, right boundary is adjacent to the left boundary, top adjacent to left, etc.
|
||||
def graph_dfs_diagonals_and_boundary_wrap(matrix):
|
||||
rows, cols = len(matrix), len(matrix[0])
|
||||
visited = set()
|
||||
# Change 1: Add 4 more diagonal directions.
|
||||
directions = ((0, 1), (0, -1), (1, 0), (-1, 0), (-1, -1), (1, 1), (1, -1), (-1, 1))
|
||||
def dfs(i, j):
|
||||
if (i, j) in visited:
|
||||
return
|
||||
visited.add((i, j))
|
||||
for direction in directions:
|
||||
# Change 2: No more boundary, use modulo to allow traversal that exceed boundaries to wrap around.
|
||||
next_i, next_j = (i + direction[0] + rows) % rows, (j + direction[1] + cols) % cols
|
||||
dfs(next_i, next_j)
|
||||
|
||||
for i in range(rows):
|
||||
for j in range(cols):
|
||||
dfs(i, j)
|
||||
|
||||
graph_dfs([
|
||||
[1, 2, 3, 4],
|
||||
[5, 6, 7, 8],
|
||||
[9, 10, 11, 12],
|
||||
])
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue