contents: reorganize algorithms section

pull/265/head
Yangshun 3 years ago
parent 38d0038fd8
commit 42c21f9819

@ -0,0 +1,2 @@
- [Grokking the Coding Interview: Patterns for Coding Questions](https://www.educative.io/courses/grokking-the-coding-interview?aff=x23W) - This course essentially expands upon the questions on this page but approaches the practicing from a questions pattern perspective rather than data structures, which is an approach I also agree with for learning and have personally used to get better at algorithmic problems. **Learn and understand patterns, not memorize answers!**
- [Master the Coding Interview: Data Structures + Algorithms](https://fxo.co/DQoD) - This Udemy bestseller is one of the highest-rated interview preparation course (4.6 stars, 21.5k ratings, 135k students) and packs **19 hours** worth of contents into it. Like Tech Interview Handbook, it goes beyond coding interviews and covers resume, non-technical interviews, negotiations. It's an all-in-one package!

@ -48,3 +48,9 @@ When you are given two arrays to process, it is common to have one index per arr
- [3Sum](https://leetcode.com/problems/3sum/)
- [Container With Most Water](https://leetcode.com/problems/container-with-most-water/)
- [Sliding Window Maximum](https://leetcode.com/problems/sliding-window-maximum/)
## Recommended courses
import AlgorithmCourses from '../\_courses/AlgorithmCourses.md'
<AlgorithmCourses />

@ -32,3 +32,9 @@ Some helpful utility snippets:
- [Counting Bits](https://leetcode.com/problems/counting-bits/)
- [Missing Number](https://leetcode.com/problems/missing-number/)
- [Reverse Bits](https://leetcode.com/problems/reverse-bits/)
## Recommended courses
import AlgorithmCourses from '../\_courses/AlgorithmCourses.md'
<AlgorithmCourses />

@ -29,6 +29,8 @@ Sometimes you do not need to store the whole DP table in memory, the last two va
- [Unique Paths](https://leetcode.com/problems/unique-paths/)
- [Jump Game](https://leetcode.com/problems/jump-game/)
## Courses
## Recommended courses
- [Grokking the Dynamic Programming Patterns for Coding Interviews](https://www.educative.io/courses/grokking-dynamic-programming-patterns-for-coding-interviews?aff=x23W)
import AlgorithmCourses from '../\_courses/AlgorithmCourses.md'
<AlgorithmCourses />

@ -15,3 +15,9 @@ To find out if two circles overlap, check that the distance between the two cent
- 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?
## Recommended courses
import AlgorithmCourses from '../\_courses/AlgorithmCourses.md'
<AlgorithmCourses />

@ -115,3 +115,9 @@ For additional tips on BFS and DFS, you can refer to this [LeetCode post](https:
- [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/)
## Recommended courses
import AlgorithmCourses from '../\_courses/AlgorithmCourses.md'
<AlgorithmCourses />

@ -8,3 +8,9 @@ title: Hash Table
- 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()`. [(Solution)](http://blog.gainlo.co/index.php/2016/08/14/uber-interview-question-map-implementation/)
## Recommended courses
import AlgorithmCourses from '../\_courses/AlgorithmCourses.md'
<AlgorithmCourses />

@ -18,3 +18,9 @@ If you require the top _k_ elements use a Min Heap of size _k_. Iterate through
- [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/)
## Recommended courses
import AlgorithmCourses from '../\_courses/AlgorithmCourses.md'
<AlgorithmCourses />

@ -38,3 +38,9 @@ def merge_overlapping_intervals(a, b):
- [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/)
## Recommended courses
import AlgorithmCourses from '../\_courses/AlgorithmCourses.md'
<AlgorithmCourses />

@ -1,6 +1,7 @@
---
id: algorithms-introduction
title: Introduction to algorithms
title: Algorithms tips
description: Here are practical tips for each algorithm topic and data structure which appear frequently in coding interviews
sidebar_label: Introduction
slug: introduction
---
@ -46,13 +47,15 @@ Hashmaps are probably the most commonly used data structure for algorithm questi
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.
## Algorithm courses
## Recommended courses
If you want more structured algorithms practice, I recommend [Educative's Grokking the Coding Interview: Patterns for Coding Questions](https://www.educative.io/courses/grokking-the-coding-interview?aff=x23W) course. This course essentially expands upon the questions here but approaches the practicing from a questions pattern perspective rather than data structures, which is an approach I agree with for learning and getting better at algorithmic problems.
import AlgorithmCourses from '../\_courses/AlgorithmCourses.md'
## References
<AlgorithmCourses />
<!-- ## References
- [Educative's Grokking the Coding Interview: Patterns for Coding Questions](https://www.educative.io/courses/grokking-the-coding-interview?aff=x23W)
- http://blog.triplebyte.com/how-to-pass-a-programming-interview
- http://www.geeksforgeeks.org/must-do-coding-questions-for-companies-like-amazon-microsoft-adobe/
- https://medium.com/basecs
- https://medium.com/basecs -->

@ -23,7 +23,7 @@ Two pointer approaches are also common for linked lists. For example:
- 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
## 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:
@ -46,3 +46,9 @@ Be familiar with the following routines because many linked list questions make
- [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/)
## Recommended courses
import AlgorithmCourses from '../\_courses/AlgorithmCourses.md'
<AlgorithmCourses />

@ -29,3 +29,9 @@ If the question asks to implement an operator such as power, squareroot or divis
- [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/)
## Recommended courses
import AlgorithmCourses from '../\_courses/AlgorithmCourses.md'
<AlgorithmCourses />

@ -35,3 +35,9 @@ transposed_matrix = zip(*matrix)
- [Rotate Image](https://leetcode.com/problems/rotate-image/)
- [Word Search](https://leetcode.com/problems/word-search/)
- [Valid Sudoku](https://leetcode.com/problems/valid-sudoku/)
## Recommended courses
import AlgorithmCourses from '../\_courses/AlgorithmCourses.md'
<AlgorithmCourses />

@ -13,6 +13,6 @@ title: Object-oriented programming
- How would you implement an Elevator system?
- How would you implement a Parking Lot system?
## Courses
## Recommended courses
- [Grokking the Object Oriented Design Interview](https://www.educative.io/courses/grokking-the-object-oriented-design-interview?aff=x23W)

@ -14,3 +14,9 @@ title: Permutation
- [Source](http://blog.gainlo.co/index.php/2016/12/23/uber-interview-questions-permutations-parentheses/)
- Given a list of arrays, return a list of arrays, where each array is a combination of one element in each given array.
- E.g. If the input is `[[1, 2, 3], [4], [5, 6]]`, the output should be `[[1, 4, 5], [1, 4, 6], [2, 4, 5], [2, 4, 6], [3, 4, 5], [3, 4, 6]]`.
## Recommended courses
import AlgorithmCourses from '../\_courses/AlgorithmCourses.md'
<AlgorithmCourses />

@ -7,3 +7,9 @@ title: Queue
- 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).
## Recommended courses
import AlgorithmCourses from '../\_courses/AlgorithmCourses.md'
<AlgorithmCourses />

@ -15,3 +15,9 @@ Recursion implicitly uses a stack. Hence all recursive approaches can be rewritt
- [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/)
## Recommended courses
import AlgorithmCourses from '../\_courses/AlgorithmCourses.md'
<AlgorithmCourses />

@ -20,3 +20,9 @@ When a given sequence is in a sorted order (be it ascending or descending), usin
- Find the minimum element in a sorted rotated array in faster than O(n) time.
- Write a function that takes a number as input and outputs the biggest number with the same set of digits.
- [Source](http://blog.gainlo.co/index.php/2017/01/20/arrange-given-numbers-to-form-the-biggest-number-possible/)
## Recommended courses
import AlgorithmCourses from '../\_courses/AlgorithmCourses.md'
<AlgorithmCourses />

@ -11,3 +11,9 @@ title: Stack
- E.g. `{ac[bb]}`, `[dklf(df(kl))d]{}` and `{[[[]]]}` are matched. But `{3234[fd` and `{df][d}` are not.
- [Source](http://blog.gainlo.co/index.php/2016/09/30/uber-interview-question-delimiter-matching/)
- Sort a stack in ascending order using an additional stack.
## Recommended courses
import AlgorithmCourses from '../\_courses/AlgorithmCourses.md'
<AlgorithmCourses />

@ -98,3 +98,9 @@ When a question is about counting the number of palindromes, a common trick is t
- [Longest Palindromic Substring](https://leetcode.com/problems/longest-palindromic-substring/)
- [Palindromic Substrings](https://leetcode.com/problems/palindromic-substrings/)
- [Encode and Decode Strings (LeetCode Premium)](https://leetcode.com/problems/encode-and-decode-strings/)
## Recommended courses
import AlgorithmCourses from '../\_courses/AlgorithmCourses.md'
<AlgorithmCourses />

@ -59,3 +59,9 @@ When a question involves a BST, the interviewer is usually looking for a solutio
- [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/)
## Recommended courses
import AlgorithmCourses from '../\_courses/AlgorithmCourses.md'
<AlgorithmCourses />

@ -21,3 +21,9 @@ Be familiar with implementing, from scratch, a `Trie` class and its `add`, `remo
- [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/)
## Recommended courses
import AlgorithmCourses from '../\_courses/AlgorithmCourses.md'
<AlgorithmCourses />

@ -6,6 +6,8 @@ description: The best practice questions to prepare for algorithmic coding inter
keywords: [algorithm, coding, interview, questions, leetcode, blind 75]
---
import AlgorithmCourses from './\_courses/AlgorithmCourses.md'
<head>
<title>Best practice questions by the author of Blind 75 | Tech Interview Handbook</title>
<meta property="og:title" content="Best practice questions by the author of Blind 75 | Tech Interview Handbook"/>
@ -23,6 +25,12 @@ When practicing, you are advised to treat it like a real coding interview and ch
I've created a [LeetCode list](https://leetcode.com/list/9h4lgwl2) for the following questions (except the Premium ones). Feel free to use it to track your practice progress.
:::tip
If you're running low on time, the [Grokking the Coding Interview: Patterns for Coding Questions](https://www.educative.io/courses/grokking-the-coding-interview?aff=x23W) course essentially expands upon the questions on this page but approaches the practicing from a questions pattern perspective rather than data structures. **Learn and understand patterns, not memorize answers!**
:::
## Week 1 - Sequences
In week 1, we will warm up by doing 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.
@ -130,4 +138,4 @@ Practically speaking the return of investment (ROI) on studying and practicing f
If you want more structured algorithms practice, I recommend the following courses:
- ["Grokking the Coding Interview: Patterns for Coding Questions" by Educative](https://www.educative.io/courses/grokking-the-coding-interview?aff=x23W) - This course essentially expands upon the questions on this page but approaches the practicing from a questions pattern perspective rather than data structures, which is an approach I also agree with for learning and have personally used to get better at algorithmic problems. **Learn and understand patterns, not memorize answers!**
<AlgorithmCourses />

@ -25,7 +25,9 @@ Coding interviews are tough. But fortunately, there's a tried and proven method
1. Decide on a [programming language](./picking-a-language.md)
1. Study [Computer Science fundamentals](./study-and-practice.md)
1. Take online courses
1. [Practice](./study-and-practice.md) solving algorithm questions
1. Do the [best practice questions](./best-practice-questions.md)
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](./mock-interviews.md)

@ -1,6 +1,6 @@
---
id: study-and-practice
title: Study and practice
title: Practical tips
description: Mastery of Computer Science fundamentals, identifying question patterns, practicing good coding style is the key to improving in coding interviews
keywords:
[
@ -23,11 +23,7 @@ keywords:
If you have been out of college for a while, it is highly advisable to review Computer Science fundamentalsAlgorithms and Data Structures. Personally, I prefer to review as I practice, so I scan through my college notes and review the various algorithms as I work on algorithm problems from LeetCode.
This [interviews repository](https://github.com/kdn251/interviews) by Kevin Naughton Jr. served as a quick refresher for me.
The Medium publication [basecs](https://medium.com/basecs) by [Vaidehi Joshi](https://medium.com/@vaidehijoshi) is also a great and light-hearted resource to recap on the various data structures and algorithms.
You can also find implementations of common data structures and algorithms using various popular languages at [TheAlgorithms](https://thealgorithms.github.io/).
I collated a list of practical tips for the common algorithm and data structure topics under the [Algorithms tips](./algorithms/introduction) section.
## Mastery through practice
@ -35,15 +31,17 @@ Next, gain familiarity and mastery of the algorithms and data structures in your
### Practice coding questions
Practice coding algorithms using your chosen language. While "Cracking the Coding Interview" is a good resource for practice, I prefer being able to type code, run it and get instant feedback. There are various Online Judges such as [LeetCode](https://leetcode.com/), [HackerRank](https://www.hackerrank.com/) and [CodeForces](http://codeforces.com/) for you to practice questions online and get used to the language. From experience, LeetCode questions are the most similar to the kind of questions being asked in interviews whereas HackerRank and CodeForces questions resemble competitive programming questions. If you practice enough LeetCode questions, there is a good chance that you would have seen/done your actual interview question (or some variant) on LeetCode before. If you are more of a visual person, [Coderust](https://www.educative.io/collection/5642554087309312/5679846214598656?aff=x23W) explains the common algorithm questions through step-by-step visualizations which makes understanding the solutions much easier.
Practice coding algorithms using your chosen language. While "Cracking the Coding Interview" is a good resource for studying, I prefer being able to type code, run it and get instant feedback. There are various Online Judges such as [LeetCode](https://leetcode.com/), [HackerRank](https://www.hackerrank.com/) and [CodeForces](http://codeforces.com/) for you to practice questions online and get used to the language. From experience, LeetCode questions are the most similar to the kind of questions being asked in interviews whereas HackerRank and CodeForces questions resemble competitive programming questions. If you practice enough LeetCode questions, there is a good chance that you would have seen/done your actual interview question (or some variant) on LeetCode before.
If you are more of a visual person, [Coderust](https://www.educative.io/collection/5642554087309312/5679846214598656?aff=x23W) explains the common algorithm questions through step-by-step visualizations which makes understanding the solutions much easier.
### Broaden exposure
Gain a broad exposure to questions from various topics. In the second half of the article I mention algorithm topics and practice questions for each topic. If you can spare the time, do around 100200 LeetCode questions of varying topics and you should be good. If you are short on time or not sure where to start, the [Best Practice Questions](./best-practice-questions.md) page tells you the best LeetCode questions to practice.
Gain a broad exposure to questions from various topics. If you can spare the time, do around 100200 LeetCode questions of varying topics and you should be good. If you are short on time or not sure where to start, the [Best practice questions](./best-practice-questions.md) page recommends you the best 50 LeetCode questions to practice.
### Identify question patterns
As of writing, LeetCode has thousands of questions available. Which should you practice? It is not a good use of time to practice too many questions as after a while, you will realize that some questions are variants of one another and involve using similar techniques you've seen before. The trick here is to identify the question pattern and the technique you can use to solve variants of this question. Once you're familiar with a pattern, you'll be able to solve dozens of problems with a technique. Some techniques include - sliding window, two pointers, matrix traversal. The ["Grokking the coding interview" course by Educative](https://www.educative.io/courses/grokking-the-coding-interview?aff=x23W) shows you more techniques.
As of writing, LeetCode has thousands of questions available. Which should you practice? It is not a good use of time to practice too many questions as after a while, you will realize that some questions are variants of one another and involve using similar techniques you've seen before. The trick here is to identify the question pattern and techniques you can use to solve variants of this question. Once you're familiar with a pattern, you'll be able to solve dozens of similar problems. Some techniques include - sliding window, two pointers, matrix traversal. The ["Grokking the Coding Interview: Patterns for Coding Questions" course by Educative](https://www.educative.io/courses/grokking-the-coding-interview?aff=x23W) shows you even more techniques and is highly recommended.
:::tip Expert tip
@ -53,14 +51,24 @@ Learn and understand patterns, not memorize answers!
### Space/time complexities
Learn and understand the time and space complexities of the common operations in your chosen language. For Python, this [page](https://wiki.python.org/moin/TimeComplexity) will come in handy. Also find out the underlying sorting algorithm that is being used in the language's `sort()` function and its time and space complexity (in Python its Timsort which is a hybrid sort). After completing a question on LeetCode, I usually add the time and space complexities of the written code as comments above the function body to remind myself to analyze the algorithm after I am done with the implementation.
Learn and understand the time and space complexities of the common operations in your chosen language. For Python, this [page](https://wiki.python.org/moin/TimeComplexity) will come in handy. Also find out the underlying sorting algorithm that is being used in the language's `sort()` function and its time and space complexity (e.g. in Python it's Timsort, which is a hybrid sort). After completing a question on LeetCode, I usually add the time and space complexities of the written code as comments above the function body to remind myself to analyze the algorithm after I am done with the implementation.
### Practice good coding style
Read up on the recommended coding style for your language and stick to it. If you have chosen Python, refer to the PEP 8 Style Guide. If you have chosen Java, refer to Google's Java Style Guide.
Read up on the recommended coding style for your language and stick to it. If you have chosen Python, refer to the [PEP 8 Style Guide](https://www.python.org/dev/peps/pep-0008/). If you have chosen Java, refer to [Google's Java Style Guide](https://google.github.io/styleguide/javaguide.html).
### Internalize the pitfalls
### Internalize language pitfalls
Find out and be familiar with the common pitfalls and caveats of the language. If you point them out during the interview and intelligently avoid falling into them, you will usually impress the interviewer and that results in bonus points for your feedback, regardless of whether the interviewer is familiar with the language or not.
**The key to interview success is practice, practice and more practice!**
:::tip
The key to interview success is practice, practice and more practice!
:::
## External resources
- This [interviews repository](https://github.com/kdn251/interviews) by Kevin Naughton Jr. served as a quick refresher for me.
- The Medium publication [basecs](https://medium.com/basecs) by [Vaidehi Joshi](https://medium.com/@vaidehijoshi) is also a great and light-hearted resource to recap on the various data structures and algorithms.
- You can also find implementations of common data structures and algorithms using various popular languages at [TheAlgorithms](https://thealgorithms.github.io/).

@ -29,38 +29,16 @@ module.exports = {
'🔥 Coding interviews': [
'coding-interview',
'picking-a-language',
{
'Study and practice': [
'study-and-practice',
'best-practice-questions',
],
},
'during-coding-interview',
'cheatsheet',
'coding-signals',
'mock-interviews',
'interviewer-cheatsheet',
{
Algorithms: [
'algorithms/algorithms-introduction',
'algorithms/array',
'algorithms/binary',
'algorithms/dynamic-programming',
'algorithms/geometry',
'algorithms/graph',
'algorithms/hash-table',
'algorithms/heap',
'algorithms/interval',
'algorithms/linked-list',
'algorithms/math',
'algorithms/matrix',
'algorithms/oop',
'algorithms/permutation',
'algorithms/queue',
'algorithms/recursion',
'algorithms/sorting-searching',
'algorithms/stack',
'algorithms/string',
'algorithms/tree',
'algorithms/trie',
],
},
],
},
'system-design',
@ -89,5 +67,33 @@ module.exports = {
// 'team-selection',
],
},
{
'Algorithms tips': [
'algorithms/algorithms-introduction',
'algorithms/array',
'algorithms/binary',
'algorithms/dynamic-programming',
'algorithms/geometry',
'algorithms/graph',
'algorithms/hash-table',
'algorithms/heap',
'algorithms/interval',
'algorithms/linked-list',
'algorithms/math',
'algorithms/matrix',
'algorithms/oop',
'algorithms/permutation',
'algorithms/queue',
'algorithms/recursion',
'algorithms/sorting-searching',
'algorithms/stack',
'algorithms/string',
'algorithms/tree',
'algorithms/trie',
],
},
{
Misc: ['interviewer-cheatsheet'],
},
],
};

Loading…
Cancel
Save