contents: reorganize algorithms section

This commit is contained in:
Yangshun
2022-02-06 15:37:53 +08:00
parent 38d0038fd8
commit 42c21f9819
26 changed files with 191 additions and 52 deletions

View File

@ -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 />

View File

@ -18,7 +18,7 @@ Some helpful utility snippets:
- 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` or `(num & (-num)) == num`.
- Swapping two variables: `num1 ^= num2; num2 ^= num1; num1 ^= num2`
- Swapping two variables: `num1 ^= num2; num2 ^= num1; num1 ^= num2`
## Corner cases
@ -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 />

View File

@ -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 />

View File

@ -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 />

View File

@ -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 />

View File

@ -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 />

View File

@ -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 />

View File

@ -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 />

View File

@ -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 -->

View File

@ -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 />

View File

@ -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 />

View File

@ -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 />

View File

@ -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)

View File

@ -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 />

View File

@ -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 />

View File

@ -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 />

View File

@ -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 />

View File

@ -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 />

View File

@ -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 />

View File

@ -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 />

View File

@ -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 />