LeetCode
LeetCode 671: Second Minimum Node In a Binary Tree
·2 mins
LeetCode
Easy
Tree
Depth-First-Search
Binary-Tree
LeetCode 671 note: the root is the minimum; the second minimum is the smallest value larger than the root, and only subtrees equal to the root need searching
LeetCode 661: Image Smoother
·2 mins
LeetCode
Easy
Array
Matrix
LeetCode 661 note: each cell becomes the floored average of the existing cells in its 3 × 3 neighborhood, written into a new matrix
LeetCode 657: Robot Return to Origin
·1 min
LeetCode
Easy
String
Simulation
LeetCode 657 note: returning to the origin means as many U as D and as many L as R
LeetCode 653: Two Sum IV - Input is a BST
·2 mins
LeetCode
Easy
Hash-Table
Two-Pointers
Tree
Depth-First-Search
LeetCode 653 note: traverse while keeping a set of seen values; finding k - val in it means a pair exists
LeetCode 645: Set Mismatch
·2 mins
LeetCode
Easy
Array
Hash-Table
Bit-Manipulation
Sorting
LeetCode 645 note: use sums: missing = sum of 1..n - sum of the set, duplicate = array sum - sum of the set
LeetCode 637: Average of Levels in Binary Tree
·1 min
LeetCode
Easy
Tree
Depth-First-Search
Breadth-First-Search
Binary-Tree
LeetCode 637 note: level-order traversal, dividing each level’s sum by its count
LeetCode 628: Maximum Product of Three Numbers
·1 min
LeetCode
Easy
Array
Math
Sorting
LeetCode 628 note: after sorting there are only two candidates: the three largest, or the two smallest (negatives) times the largest
LeetCode 606: Construct String from Binary Tree
·1 min
LeetCode
Medium
String
Tree
Depth-First-Search
Binary-Tree
LeetCode 606 note: output in pre-order, keeping an empty () when only the left subtree is missing, and omitting the right parentheses when it is empty
LeetCode 605: Can Place Flowers
·2 mins
LeetCode
Easy
Array
Greedy
LeetCode 605 note: scan left to right and plant in any empty plot whose neighbors are empty; a new flower blocks the next plot, so actually update the array
LeetCode 599: Minimum Index Sum of Two Lists
·2 mins
LeetCode
Easy
Array
Hash-Table
String
LeetCode 599 note: map list1’s strings to indices, sum both indices while scanning list2, and keep every string with the minimum sum
LeetCode 598: Range Addition II
·2 mins
LeetCode
Easy
Array
Math
LeetCode 598 note: every operation covers the top-left corner, so the most-incremented cells form the intersection of all operations: min(a) × min(b)
LeetCode 594: Longest Harmonious Subsequence
·1 min
LeetCode
Easy
Array
Hash-Table
Sliding-Window
Sorting
LeetCode 594 note: subsequences need not be contiguous, so just count; for each x add the counts of x and x + 1