Editorial: LC premium set 4
Good for whiteboarding
- 1246. Palindrome Removal
- Sliding Puzzle
- Shortest Common Supersequence
- Pour Water
- Shortest Way to Form String
- Design In-Memory File System
- Palindrome Pairs
- Recover a Tree From Preorder Traversal
- Count Different Palindromic Subsequences
Word Squares
- Brute force TLE
Max Chunks To Make Sorted II
- My gut feeling was incorrect
Critical Connections in a Network
- What if we want to find articulation points?
Cherry Pickup
- Took me too long
String Transforms Into Another String
- Multiple attempts
Editorial: LC premium set 3
Good for whiteboarding
- 1059. All Paths from Source Lead to Destination
- Stepping Numbers
- Minimum Window Subsequence
- Lowest Common Ancestor of a Binary Tree IV
Campus Bikes II
- Backtracking gives TLE
Binary Tree Vertical Order Traversal
- O(n) time
Minimum Knight Moves
- Optimization condition
Verify Preorder Sequence in Binary Search Tree
- O(1) extra space
Number Of Corner Rectangles
- My gut feeling gives TLE
IP to CIDR
- Took me too long
Editorial: LC premium set 2
Good for whiteboarding
- Longest Line of Consecutive One in Matrix
- Mutliple solutions
- Bomb Enemy
- Closest Binary Search Tree Value II
- Add Bold Tag in String
- 3Sum Smaller
- Insert into a Sorted Circular Linked List
- Binary Tree Longest Consecutive Sequence II
Rearrange String k Distance Apart
- Took me too long
LFU Cache
- Solve it with LL
Check If a String Is a Valid Sequence from Root to Leaves Path in a Binary Tree
- My optimization was wrong
Candy Crush
- Official solution is cleaner than mine
Tree Diameter
- Multiple solutions
Editorial: LC premium set 1
Good for whiteboarding
On FFT
Original video
- Eval a polynomical A(x) at x0 : Horner’s rule
- Mutlply two polys:
- Closed form at O(n^2) naively -> O(nlogn) possible
- Equivalent to convolution of vectors A * reverse(B) - inner products of all possible shifts
- Poly representations:
- Samples for n points with all distince xs.
- Convert between this and coefficient form in O(nlogn)
- Sampling n points takes O(n^2) in total
- A sequence of n roots
- Samples for n points with all distince xs.
- Eval A(x) for x in X: D&C by even/odd i
- A(x) = A_even(x^2) + x * A_odd(x^2)
- Derive the recursion and cost => draw the recursion tree and we see it is still n^2
- Square a number on the unit circle on the complex plane
- FFT is the d&c algo for DFT (coefficent to sample form)
- Fast poly multiplicatin: FFT(A) * FFA(B) and then do inverse FFT
- Similar techique
Editorial: Coding set 18
Good for whiteboarding
- Number of Sets of K Non-Overlapping Line Segments
- Repeated String Match
- Spiral Matrix III
- Find And Replace in String
- Online Election
- Previous Permutation With One Swap
- Minimum Number of Days to Make m Bouquets
- Vowel Spellchecker
- Number of Nodes in the Sub-Tree With the Same Label
Check If Word Is Valid After Substitutions
- First attempt TLE
Mini Parser
- Corner cases
Stamping The Sequence
- My optimization was wrong
Largest Merge Of Two Strings
- My optimization was wrong
Remove Zero Sum Consecutive Nodes from Linked List
Editorial: Coding set 17
Good for whiteboarding
- Maximum XOR of Two Numbers in an Array
- Map Sum Pairs
- Find the Longest Substring Containing Vowels in Even Counts
- Diagonal Traverse II
- Remove Sub-Folders from the Filesystem
- Course Schedule IV
- Number of Subsequences That Satisfy the Given Sum Condition
- Search Suggestions System
- Number of Good Leaf Nodes Pairs
- Maximum Score from Performing Multiplication Operations
- Correct a Binary Tree
Shopping Offers
- First attempt TLE
Maximum Number of Events That Can Be Attended
- My gut feeling was wrong
Shortest Unsorted Continuous Subarray
- First attempt WA
Path with Maximum Probability
- First attempt TLE
Editorial: Coding set 16
Good for whiteboarding
- Sequential Digits
- Stone Game II
- Maximum Subarray Sum with One Deletion
- 1202. Smallest String With Swaps
- Reverse Substrings Between Each Pair of Parentheses
- Greatest Sum Divisible by Three
- Count Number of Nice Subarrays
- Most Profit Assigning Work
- Minimum Cost Tree From Leaf Values
- Filling Bookcase Shelves
- Delete Columns to Make Sorted II
- 3Sum With Multiplicity
Can I Win
- My algo was wrong
Most Stones Removed with Same Row or Column
- How to prove it works?
[Number of Closed Islands] (https://leetcode.com/submissions/detail/403350247/)
- My optimization was wrong
Editorial: Coding set 15
Good for whiteboarding
- Find Eventual Safe States
- Insert Interval
- Regions Cut By Slashes
- Convert to Base -2
- 935. Knight Dialer
- Guess Number Higher or Lower II
- Adding Two Negabinary Numbers
- 1296. Divide Array in Sets of K Consecutive Numbers
Minimum Area Rectangle
- First attempt got TLE
- Multiple solutions
Last Stone Weight II
- My gut feeling was wrong
1124. Longest Well-Performing Interval
- My algo was wrong
Editorial: Coding set 14
Good for whiteboarding
- Path In Zigzag Labelled Binary Tree
- Simplify Path
- Push Dominoes
- Unique Substrings in Wraparound String
- 1361. Validate Binary Tree Nodes
Champagne Tower
- My first attempt was wrong
Number of Subarrays with Bounded Maximum
- Corner case
988. Smallest String Starting From Leaf
- My optimization was wrong
Additive Number
- First attempt missed a corner case
Super Pow
- My gut feeling was wrong
Longest Word in Dictionary through Deleting
- Official insight is cleaner than mine
- First attempt missed a corner case
Editorial: Coding set 13
Editorial: Coding set 12
Good for whiteboarding
- Find All Duplicates in an Array
- Random Flip Matrix
- Number of Atoms
- Minimize Max Distance to Gas Station
- Confusing Number II
The Maze III
- My optimization was wrong
Coin Path
- My optimization was wrong
Minimum Number of Days to Eat N Oranges
- Took me too long
Maximum Number of Non-Overlapping Substrings
- My optimization was wrong
Editorial: Coding set 11
Good for whiteboarding
Student Attendance Record II
- Official insight cleaner than mine
Rectangle Area II
- Took me too long to figure out the decomposition
Trapping Rain Water II
- Unable to come up with the insight myself
Russian Doll Envelopes
- My algo was incorrect
Editorial: Coding set 10
Editorial: Coding set 9
Good for whiteboarding
- Basic Calculator III
- Build Array Where You Can Find The Maximum Exactly K Comparisons
- Minimum Distance to Type a Word Using Two Fingers
- Longest Chunked Palindrome Decomposition
- 24 Game
Find the Kth Smallest Sum of a Matrix With Sorted Rows
- My gut feeling was wrong
String Compression II
- My algo was wrong
Find the Closest Palindrome
- Corner cases
Minimum Cost to Make at Least One Valid Path in a Grid
- Failed to see the insight
1096. Brace Expansion II
- Compare and contrast with Parsing A Boolean Expression
Minimum Number of Increments on Subarrays to Form a Target Array
- Took me too long
642. Design Search Autocomplete System
- 2 WAs
Numbers With Repeated Digits
- Took me too long
Editorial: Coding set 8
Maximum Length of Pair Chain
- How to prove we can do greedy
Circular Array Loop
- My gut feeling was wrong
Making File Names Unique
- My optimization was wrong
Monotone Increasing Digits
- Multiple solutions
Binary Subarrays With Sum
- Multiple solutions
Matchsticks to Square
- A lot trickier than it appears!
Editorial: Coding set 7
Good for whiteboarding
- 956. Tallest Billboard
- 600. Non-negative Integers without Consecutive Ones
- 920. Number of Music Playlists
- 995. Minimum Number of K Consecutive Bit Flips
- 664. Strange Printer
- Print Words Vertically
- Number of Ways of Cutting a Pizza
- Max Dot Product of Two Subsequences
- Arithmetic Slices II - Subsequence
- Paint House III
952. Largest Component Size by Common Factor
- First attempt missed 1 corner case
- Python is too slow for this problem
902. Numbers At Most N Given Digit Set
- First attempt missed 1 corner case
- Multiple solutions
Ways to Split Array Into Three Subarrays
- 2 WAs
Replace the Substring for Balanced String
- First attempt WA
Maximum Profit in Job Scheduling
- Took me too long
Editorial: Coding set 6
Good for whiteboarding
- 871. Minimum Number of Refueling Stops
- Multiple ideas
- Sum of Mutated Array Closest to Target
- Get Equal Substrings Within Budget
- Video Stitching
- Smallest Integer Divisible by K
- Minimum Area Rectangle II
- 1238. Circular Permutation in Binary Representation
- Construct the Lexicographically Largest Valid Sequence
- Maximum Score From Removing Substrings
- 233. Number of Digit One
- Smallest Integer Divisible by K
- Minimum Area Rectangle II
- 1238. Circular Permutation in Binary Representation
- Minimum Number of Taps to Open to Water a Garden
RLE Iterator
- The official solution is cleaner than mine
On Uber's Cadence
Checked 10+ workflow engines. Here are my conclusions:
- It is not designed for high traffic (> 100 per sec) + short lived task case (< 10 sec). At most one requirement can be satisfied
- However, WE should support many executing tasks, e.g., 100k tasks managed by the workflow engine
- Evolution lineage
AWS Simple Workflow -> Uber Cadence -> Temporal
-> AWS Step Function
Concepts
- Workflow: similiar to the coordinator in saga. Its code is hosted on the workflow worker, which is your process
- The communication between workflow worker and cadence service is encapsulated in a decision task (also called workflow task), e.g., when an external event happens to the workflow, a decision task will be created and dispatched to WW
- Activity: similar to the sub txn component in saga. Its code is hosted on the activity worker, which is your process and often the same process as the workflow worker
- The communciation between activity worker and cadence service is encapsulated in the activity task, e.g., WW sends a ScheduleActivityTask to cadence, which will dispatch a corresponding activity task to the AW
- Execution history: persistent log to support exactly-once, all-or-nothing semantics. All task data will be persisted too to support replay during recovery
Architecture
- Front end: API gateway
- Matching service: task scheduling, dispatching, and task list
- backed by task storage
- History service: workflow state, timer q, and transfer q
- backed by event, workflow, visibility storage
Editorial: Coding set 5
Good for whiteboarding
- 629. K Inverse Pairs Array
- 878. Nth Magical Number
- 887. Super Egg Drop
- Sell Diminishing-Valued Colored Balls
- Patching Array
- Jump Game VI
780. Reaching Points
- Many corner cases
Minimum Domino Rotations For Equal Row
- My gut feeling was wrong
862. Shortest Subarray with Sum at Least K
- My DP appoarch didn’t work
927. Three Equal Parts
- Corner cases
906. Super Palindromes
- Corner cases
Decoded String at Index
- Official insight cleaner than mine
Dota2 Senate
- O(n) runtime
Perfect Rectangle
Minimum Score Triangulation of Polygon
- My gut feeling was wrong