diff --git a/10/20/m1020.swift b/10/20/m1020.swift new file mode 100644 index 0000000..b3d5a50 --- /dev/null +++ b/10/20/m1020.swift @@ -0,0 +1,53 @@ +// Solved: +// (M) Number of Enclaves +// https://leetcode.com/problems/number-of-enclaves/ + +class Solution { + typealias Coord = (x: Int, y: Int) + + private func _processEnclave(_ grid: inout [[Int]], _ x: Int, _ y: Int) -> Int { + let xmax = grid.count - 1, ymax = grid[0].count - 1 + var tile: [Coord] = [(x, y)] + var nEnclave = 0 + + grid[x][y] = 0 + while !tile.isEmpty { + let c = tile.removeLast() + // If the tile is on bound, this is not an enclave + if c.x == 0 || c.y == 0 || c.x == xmax || c.y == ymax { nEnclave = -1 } + if nEnclave >= 0 { nEnclave += 1 } + if c.x > 0 && grid[c.x - 1][c.y] == 1 { grid[c.x - 1][c.y] = 0; tile.append((c.x - 1, c.y)) } + if c.y > 0 && grid[c.x][c.y - 1] == 1 { grid[c.x][c.y - 1] = 0; tile.append((c.x, c.y - 1)) } + if c.x < xmax && grid[c.x + 1][c.y] == 1 { grid[c.x + 1][c.y] = 0; tile.append((c.x + 1, c.y)) } + if c.y < ymax && grid[c.x][c.y + 1] == 1 { grid[c.x][c.y + 1] = 0; tile.append((c.x, c.y + 1)) } + } + + return nEnclave > 0 ? nEnclave : 0 + } + + func numEnclaves(_ grid: [[Int]]) -> Int { + var g = grid + var res = 0 + + // Obvious case - no inner tiles at all + if g.count <= 2 || g[0].count <= 2 { return 0 } + + for i in 1.. | -| 3 | ![M](img/M.png) [Longest Substring Without Repeating Characters](https://leetcode.com/problems/longest-substring-without-repeating-characters/) | | | -| 5 | ![M](img/M.png) [Longest Palindromic Substring](https://leetcode.com/problems/longest-palindromic-substring/) | | | -| 7 | ![M](img/M.png) [Reverse Integer](https://leetcode.com/problems/reverse-integer/) | | | -| 13 | ![E](img/E.png) [Roman to Integer](https://leetcode.com/problems/roman-to-integer/) | | | -| 25 | ![H](img/H.png) [Reverse Nodes in k-Group](https://leetcode.com/problems/reverse-nodes-in-k-group/) | | | -| 30 | ![H](img/H.png) [Substring with Concatenation of All Words](https://leetcode.com/problems/substring-with-concatenation-of-all-words/) | | | -| 33 | ![M](img/M.png) [Search in Rotated Sorted Array](https://leetcode.com/problems/search-in-rotated-sorted-array/) | | | -| 34 | ![M](img/M.png) [Find First and Last Position of Element in Sorted Array](https://leetcode.com/problems/find-first-and-last-position-of-element-in-sorted-array/) | | | -| 35 | ![E](img/E.png) [Search Insert Position](https://leetcode.com/problems/search-insert-position/) | | | -| 41 | ![H](img/H.png) [First Missing Positive](https://leetcode.com/problems/first-missing-positive/) | | | -| 50 | ![M](img/M.png) [Pow(x, n)](https://leetcode.com/problems/powx-n/) | | | -| 60 | ![H](img/H.png) [Permutation Sequence](https://leetcode.com/problems/permutation-sequence/) | | | -| 62 | ![M](img/M.png) [Unique Paths](https://leetcode.com/problems/unique-paths/) | | | -| 67 | ![E](img/E.png) [Add Binary](https://leetcode.com/problems/add-binary/) | | | -| 69 | ![E](img/E.png) [Sqrt(x)](https://leetcode.com/problems/sqrtx/) | | | -| 74 | ![M](img/M.png) [Search a 2D Matrix](https://leetcode.com/problems/search-a-2d-matrix/) | | | -| 86 | ![M](img/M.png) [Partition List](https://leetcode.com/problems/partition-list/) | | | -| 88 | ![E](img/E.png) [Merge Sorted Array](https://leetcode.com/problems/merge-sorted-array/) | | | -| 89 | ![M](img/M.png) [Gray Code](https://leetcode.com/problems/gray-code/) | | | -| 92 | ![M](img/M.png) [Reverse Linked List II](https://leetcode.com/problems/reverse-linked-list-ii/) | | | -| 102 | ![M](img/M.png) [Binary Tree Level Order Traversal](https://leetcode.com/problems/binary-tree-level-order-traversal/) | | | -| 114 | ![M](img/M.png) [Flatten Binary Tree to Linked List](https://leetcode.com/problems/flatten-binary-tree-to-linked-list/) | | | -| 118 | ![E](img/E.png) [Pascal's Triangle](https://leetcode.com/problems/pascals-triangle/) | | | -| 119 | ![E](img/E.png) [Pascal's Triangle II](https://leetcode.com/problems/pascals-triangle-ii/) | | | -| 136 | ![E](img/E.png) [Single Number](https://leetcode.com/problems/single-number/) | | | -| 137 | ![M](img/M.png) [Single Number II](https://leetcode.com/problems/single-number-ii/) | | | -| 153 | ![M](img/M.png) [Find Minimum in Rotated Sorted Array](https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/) | | | -| 167 | ![M](img/M.png) [Two Sum II - Input Array Is Sorted](https://leetcode.com/problems/two-sum-ii-input-array-is-sorted/) | | | -| 172 | ![M](img/M.png) [Factorial Trailing Zeroes](https://leetcode.com/problems/factorial-trailing-zeroes/) | | | -| 200 | ![M](img/M.png) [Number of Islands](https://leetcode.com/problems/number-of-islands/) | | | -| 202 | ![E](img/E.png) [Happy Number](https://leetcode.com/problems/happy-number/) | | | -| 204 | ![M](img/M.png) [Count Primes](https://leetcode.com/problems/count-primes/) | | | -| 206 | ![E](img/E.png) [Reverse Linked List](https://leetcode.com/problems/reverse-linked-list/) | | | -| 215 | ![M](img/M.png) [Kth Largest Element in an Array](https://leetcode.com/problems/kth-largest-element-in-an-array/) | | | -| 234 | ![E](img/E.png) [Palindrome Linked List](https://leetcode.com/problems/palindrome-linked-list/) | | | -| 235 | ![E](img/E.png) [Lowest Common Ancestor of a Binary Search Tree](https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-search-tree/) | | | -| 236 | ![M](img/M.png) [Lowest Common Ancestor of a Binary Tree](https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree/) | | | -| 240 | ![M](img/M.png) [Search a 2D Matrix II](https://leetcode.com/problems/search-a-2d-matrix-ii/) | | | -| 242 | ![E](img/E.png) [Valid Anagram](https://leetcode.com/problems/valid-anagram/) | | | -| 260 | ![M](img/M.png) [Single Number III](https://leetcode.com/problems/single-number-iii/) | | | -| 263 | ![E](img/E.png) [Ugly Number](https://leetcode.com/problems/ugly-number/) | | | -| 264 | ![M](img/M.png) [Ugly Number II](https://leetcode.com/problems/ugly-number-ii/) | | | -| 278 | ![E](img/E.png) [First Bad Version](https://leetcode.com/problems/first-bad-version/) | | | -| 304 | ![M](img/M.png) [Range Sum Query 2D - Immutable](https://leetcode.com/problems/range-sum-query-2d-immutable/) | | | -| 307 | ![M](img/M.png) [Range Sum Query - Mutable](https://leetcode.com/problems/range-sum-query-mutable/) | | | -| 315 | ![H](img/H.png) [Count of Smaller Numbers After Self](https://leetcode.com/problems/count-of-smaller-numbers-after-self/) | | | -| 326 | ![E](img/E.png) [Power of Three](https://leetcode.com/problems/power-of-three/) | | | -| 342 | ![E](img/E.png) [Power of Four](https://leetcode.com/problems/power-of-four/) | | | -| 350 | ![E](img/E.png) [Intersection of Two Arrays II](https://leetcode.com/problems/intersection-of-two-arrays-ii/) | | | -| 367 | ![E](img/E.png) [Valid Perfect Square](https://leetcode.com/problems/valid-perfect-square/) | | | -| 374 | ![E](img/E.png) [Guess Number Higher or Lower](https://leetcode.com/problems/guess-number-higher-or-lower/) | | | -| 377 | ![M](img/M.png) [Combination Sum IV](https://leetcode.com/problems/combination-sum-iv/) | | | -| 378 | ![M](img/M.png) [Kth Smallest Element in a Sorted Matrix](https://leetcode.com/problems/kth-smallest-element-in-a-sorted-matrix/) | | | -| 383 | ![E](img/E.png) [Ransom Note](https://leetcode.com/problems/ransom-note/) | | | -| 387 | ![E](img/E.png) [First Unique Character in a String](https://leetcode.com/problems/first-unique-character-in-a-string/) | | | -| 429 | ![M](img/M.png) [N-ary Tree Level Order Traversal](https://leetcode.com/problems/n-ary-tree-level-order-traversal/) | | | -| 441 | ![E](img/E.png) [Arranging Coins](https://leetcode.com/problems/arranging-coins/) | | | -| 462 | ![M](img/M.png) [Minimum Moves to Equal Array Elements II](https://leetcode.com/problems/minimum-moves-to-equal-array-elements-ii/) | | | -| 633 | ![M](img/M.png) [Sum of Square Numbers](https://leetcode.com/problems/sum-of-square-numbers/) | | | -| 637 | ![E](img/E.png) [Average of Levels in Binary Tree](https://leetcode.com/problems/average-of-levels-in-binary-tree/) | | | -| 668 | ![H](img/H.png) [Kth Smallest Number in Multiplication Table](https://leetcode.com/problems/kth-smallest-number-in-multiplication-table/) | | | -| 695 | ![M](img/M.png) [Max Area of Island](https://leetcode.com/problems/max-area-of-island/) | | | -| 704 | ![E](img/E.png) [Binary Search](https://leetcode.com/problems/binary-search/) | | | -| 729 | ![M](img/M.png) [My Calendar I](https://leetcode.com/problems/my-calendar-i/) | | | -| 733 | ![E](img/E.png) [Flood Fill](https://leetcode.com/problems/flood-fill/) | | | -| 744 | ![E](img/E.png) [Find Smallest Letter Greater Than Target](https://leetcode.com/problems/find-smallest-letter-greater-than-target/) | | | -| 786 | ![M](img/M.png) [K-th Smallest Prime Fraction](https://leetcode.com/problems/k-th-smallest-prime-fraction/) | | | -| 804 | ![E](img/E.png) [Unique Morse Code Words](https://leetcode.com/problems/unique-morse-code-words/) | | | -| 814 | ![M](img/M.png) [Binary Tree Pruning](https://leetcode.com/problems/binary-tree-pruning/) | | | -| 852 | ![M](img/M.png) [Peak Index in a Mountain Array](https://leetcode.com/problems/peak-index-in-a-mountain-array/) | | | -| 858 | ![M](img/M.png) [Mirror Reflection](https://leetcode.com/problems/mirror-reflection/) | | | -| 867 | ![E](img/E.png) [Transpose Matrix](https://leetcode.com/problems/transpose-matrix/) | | | -| 871 | ![H](img/H.png) [Minimum Number of Refueling Stops](https://leetcode.com/problems/minimum-number-of-refueling-stops/) | | | -| 890 | ![M](img/M.png) [Find and Replace Pattern](https://leetcode.com/problems/find-and-replace-pattern/) | | | -| 967 | ![M](img/M.png) [Numbers With Same Consecutive Differences](https://leetcode.com/problems/numbers-with-same-consecutive-differences/) | | | -| 987 | ![H](img/H.png) [Vertical Order Traversal of a Binary Tree](https://leetcode.com/problems/vertical-order-traversal-of-a-binary-tree/) | | | -| 1048 | ![M](img/M.png) [Longest String Chain](https://leetcode.com/problems/longest-string-chain/) | | | -| 1175 | ![E](img/E.png) [Prime Arrangements](https://leetcode.com/problems/prime-arrangements/) | | | -| 1250 | ![H](img/H.png) [Check If It Is a Good Array](https://leetcode.com/problems/check-if-it-is-a-good-array/) | | | -| 1254 | ![M](img/M.png) [Number of Closed Islands](https://leetcode.com/problems/number-of-closed-islands/) | | | -| 1332 | ![E](img/E.png) [Remove Palindromic Subsequences](https://leetcode.com/problems/remove-palindromic-subsequences/) | | | -| 1337 | ![E](img/E.png) [The K Weakest Rows in a Matrix](https://leetcode.com/problems/the-k-weakest-rows-in-a-matrix/) | | | -| 1338 | ![M](img/M.png) [Reduce Array Size to The Half](https://leetcode.com/problems/reduce-array-size-to-the-half/) | | | -| 1346 | ![E](img/E.png) [Check If N and Its Double Exist](https://leetcode.com/problems/check-if-n-and-its-double-exist/) | | | -| 1351 | ![E](img/E.png) [Count Negative Numbers in a Sorted Matrix](https://leetcode.com/problems/count-negative-numbers-in-a-sorted-matrix/) | | | -| 1385 | ![E](img/E.png) [Find the Distance Value Between Two Arrays](https://leetcode.com/problems/find-the-distance-value-between-two-arrays/) | | | -| 1423 | ![M](img/M.png) [Maximum Points You Can Obtain from Cards](https://leetcode.com/problems/maximum-points-you-can-obtain-from-cards/) | | | -| 1447 | ![M](img/M.png) [Simplified Fractions](https://leetcode.com/problems/simplified-fractions/) | | | -| 1448 | ![M](img/M.png) [Count Good Nodes in Binary Tree](https://leetcode.com/problems/count-good-nodes-in-binary-tree/) | | | -| 1480 | ![E](img/E.png) [Running Sum of 1d Array](https://leetcode.com/problems/running-sum-of-1d-array/) | | | -| 1539 | ![E](img/E.png) [Kth Missing Positive Number](https://leetcode.com/problems/kth-missing-positive-number/) | | | -| 1608 | ![E](img/E.png) [Special Array With X Elements Greater Than or Equal X](https://leetcode.com/problems/special-array-with-x-elements-greater-than-or-equal-x/) | | | -| 1647 | ![M](img/M.png) [Minimum Deletions to Make Character Frequencies Unique](https://leetcode.com/problems/minimum-deletions-to-make-character-frequencies-unique/) | | | -| 1689 | ![M](img/M.png) [Partitioning Into Minimum Number Of Deci-Binary Numbers](https://leetcode.com/problems/partitioning-into-minimum-number-of-deci-binary-numbers/) | | | -| 1710 | ![E](img/E.png) [Maximum Units on a Truck](https://leetcode.com/problems/maximum-units-on-a-truck/) | | | -| 1855 | ![M](img/M.png) [Maximum Distance Between a Pair of Values](https://leetcode.com/problems/maximum-distance-between-a-pair-of-values/) | | | -| 2091 | ![M](img/M.png) [Removing Minimum and Maximum From Array](https://leetcode.com/problems/removing-minimum-and-maximum-from-array/) | | | -| 2183 | ![H](img/H.png) [Count Array Pairs Divisible by K](https://leetcode.com/problems/count-array-pairs-divisible-by-k/) | | | -| 2197 | ![H](img/H.png) [Replace Non-Coprime Numbers in Array](https://leetcode.com/problems/replace-non-coprime-numbers-in-array/) | | | -| 2280 | ![M](img/M.png) [Minimum Lines to Represent a Line Chart](https://leetcode.com/problems/minimum-lines-to-represent-a-line-chart/) | | | - -### Basic algorithm implementations - -#### Binary indexed tree (Fenwick tree) - -| No. | Solutions where implemented | Lang | Notes | -|:---:|-----------------------------|:----:|-------| -| 315 | Count of Smaller Numbers After Self | ![](img/sw.png) ![](img/c.png) | Tree for counting numbers less than X | - -#### Binary search - -| No. | Solutions where implemented | Lang | Notes | -|:---:|-----------------------------|:----:|-------| -| 34 | Find First and Last Position of Element in Sorted Array | ![](img/py.png) ![](img/cpp.png) | Search for leftmost and rightmost in series of equals | -| 35 | Search Insert Position | ![](img/py.png) | Search for leftmost | -| 74 | Search a 2D Matrix | ![](img/py.png) ![](img/cpp.png) | Simple search with linear indexing of 2D matrix | -| 240 | Search a 2D Matrix II | ![](img/cpp.png) | Simple search | -| 704 | Binary Search | ![](img/py.png) ![](img/sw.png) | Simple search | - -#### Greatest common divisor (GCD) - -| No. | Solutions where implemented | Lang | Notes | -|:---:|-----------------------------|:----:|-------| -| 1447 | Simplified Fractions | ![](img/cpp.png) | | -| 2280 | Minimum Lines to Represent a Line Chart | ![](img/cpp.png) | | - -#### Single-linked list - -| No. | Solutions where implemented | Lang | Notes | -|:---:|-----------------------------|:----:|-------| -| 25 | Reverse Nodes in k-Group | ![](img/py.png) | | -| 92 | Reverse Linked List II | ![](img/py.png) | | - - -### Other helpers - -| Helper | Solution | Lang | -|--------|----------|:----:| -| `Py` implementation of ListNode's `__str__` and `__repr__` | 25. Reverse Nodes in k-Group | | -| Dynamic array | 637. Average of Levels in Binary Tree | | -| `Swift` queue using single-linked list | 695. Max Area of Island | | -| Building TreeNode’s tree from array | 814. Binary Tree Pruning | | -| Building TreeNode's tree from array | 987. Vertical Order Traversal of a Binary Tree | | +Here is the list of solved problems. Language images are clickable and lead to the solution file. + +| No. | Description (link to Leetcode) | Explanation | Lang | +|:----:|-------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------|:--------------------------------:| +| 2 | ![M](img/M.png) [Add Two Numbers](https://leetcode.com/problems/add-two-numbers/) | | | +| 3 | ![M](img/M.png) [Longest Substring Without Repeating Characters](https://leetcode.com/problems/longest-substring-without-repeating-characters/) | | | +| 5 | ![M](img/M.png) [Longest Palindromic Substring](https://leetcode.com/problems/longest-palindromic-substring/) | | | +| 7 | ![M](img/M.png) [Reverse Integer](https://leetcode.com/problems/reverse-integer/) | | | +| 13 | ![E](img/E.png) [Roman to Integer](https://leetcode.com/problems/roman-to-integer/) | | | +| 25 | ![H](img/H.png) [Reverse Nodes in k-Group](https://leetcode.com/problems/reverse-nodes-in-k-group/) | | | +| 30 | ![H](img/H.png) [Substring with Concatenation of All Words](https://leetcode.com/problems/substring-with-concatenation-of-all-words/) | | | +| 33 | ![M](img/M.png) [Search in Rotated Sorted Array](https://leetcode.com/problems/search-in-rotated-sorted-array/) | | | +| 34 | ![M](img/M.png) [Find First and Last Position of Element in Sorted Array](https://leetcode.com/problems/find-first-and-last-position-of-element-in-sorted-array/) | | | +| 35 | ![E](img/E.png) [Search Insert Position](https://leetcode.com/problems/search-insert-position/) | | | +| 41 | ![H](img/H.png) [First Missing Positive](https://leetcode.com/problems/first-missing-positive/) | | | +| 50 | ![M](img/M.png) [Pow(x, n)](https://leetcode.com/problems/powx-n/) | | | +| 60 | ![H](img/H.png) [Permutation Sequence](https://leetcode.com/problems/permutation-sequence/) | | | +| 62 | ![M](img/M.png) [Unique Paths](https://leetcode.com/problems/unique-paths/) | | | +| 67 | ![E](img/E.png) [Add Binary](https://leetcode.com/problems/add-binary/) | | | +| 69 | ![E](img/E.png) [Sqrt(x)](https://leetcode.com/problems/sqrtx/) | | | +| 74 | ![M](img/M.png) [Search a 2D Matrix](https://leetcode.com/problems/search-a-2d-matrix/) | | | +| 86 | ![M](img/M.png) [Partition List](https://leetcode.com/problems/partition-list/) | | | +| 88 | ![E](img/E.png) [Merge Sorted Array](https://leetcode.com/problems/merge-sorted-array/) | | | +| 89 | ![M](img/M.png) [Gray Code](https://leetcode.com/problems/gray-code/) | | | +| 92 | ![M](img/M.png) [Reverse Linked List II](https://leetcode.com/problems/reverse-linked-list-ii/) | | | +| 102 | ![M](img/M.png) [Binary Tree Level Order Traversal](https://leetcode.com/problems/binary-tree-level-order-traversal/) | | | +| 114 | ![M](img/M.png) [Flatten Binary Tree to Linked List](https://leetcode.com/problems/flatten-binary-tree-to-linked-list/) | | | +| 118 | ![E](img/E.png) [Pascal's Triangle](https://leetcode.com/problems/pascals-triangle/) | | | +| 119 | ![E](img/E.png) [Pascal's Triangle II](https://leetcode.com/problems/pascals-triangle-ii/) | | | +| 136 | ![E](img/E.png) [Single Number](https://leetcode.com/problems/single-number/) | | | +| 137 | ![M](img/M.png) [Single Number II](https://leetcode.com/problems/single-number-ii/) | | | +| 153 | ![M](img/M.png) [Find Minimum in Rotated Sorted Array](https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/) | | | +| 167 | ![M](img/M.png) [Two Sum II - Input Array Is Sorted](https://leetcode.com/problems/two-sum-ii-input-array-is-sorted/) | | | +| 172 | ![M](img/M.png) [Factorial Trailing Zeroes](https://leetcode.com/problems/factorial-trailing-zeroes/) | | | +| 200 | ![M](img/M.png) [Number of Islands](https://leetcode.com/problems/number-of-islands/) | | | +| 202 | ![E](img/E.png) [Happy Number](https://leetcode.com/problems/happy-number/) | | | +| 204 | ![M](img/M.png) [Count Primes](https://leetcode.com/problems/count-primes/) | | | +| 206 | ![E](img/E.png) [Reverse Linked List](https://leetcode.com/problems/reverse-linked-list/) | | | +| 215 | ![M](img/M.png) [Kth Largest Element in an Array](https://leetcode.com/problems/kth-largest-element-in-an-array/) | | | +| 234 | ![E](img/E.png) [Palindrome Linked List](https://leetcode.com/problems/palindrome-linked-list/) | | | +| 235 | ![E](img/E.png) [Lowest Common Ancestor of a Binary Search Tree](https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-search-tree/) | | | +| 236 | ![M](img/M.png) [Lowest Common Ancestor of a Binary Tree](https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree/) | | | +| 240 | ![M](img/M.png) [Search a 2D Matrix II](https://leetcode.com/problems/search-a-2d-matrix-ii/) | | | +| 242 | ![E](img/E.png) [Valid Anagram](https://leetcode.com/problems/valid-anagram/) | | | +| 260 | ![M](img/M.png) [Single Number III](https://leetcode.com/problems/single-number-iii/) | | | +| 263 | ![E](img/E.png) [Ugly Number](https://leetcode.com/problems/ugly-number/) | | | +| 264 | ![M](img/M.png) [Ugly Number II](https://leetcode.com/problems/ugly-number-ii/) | | | +| 278 | ![E](img/E.png) [First Bad Version](https://leetcode.com/problems/first-bad-version/) | | | +| 304 | ![M](img/M.png) [Range Sum Query 2D - Immutable](https://leetcode.com/problems/range-sum-query-2d-immutable/) | | | +| 307 | ![M](img/M.png) [Range Sum Query - Mutable](https://leetcode.com/problems/range-sum-query-mutable/) | | | +| 315 | ![H](img/H.png) [Count of Smaller Numbers After Self](https://leetcode.com/problems/count-of-smaller-numbers-after-self/) | | | +| 326 | ![E](img/E.png) [Power of Three](https://leetcode.com/problems/power-of-three/) | | | +| 342 | ![E](img/E.png) [Power of Four](https://leetcode.com/problems/power-of-four/) | | | +| 350 | ![E](img/E.png) [Intersection of Two Arrays II](https://leetcode.com/problems/intersection-of-two-arrays-ii/) | | | +| 367 | ![E](img/E.png) [Valid Perfect Square](https://leetcode.com/problems/valid-perfect-square/) | | | +| 374 | ![E](img/E.png) [Guess Number Higher or Lower](https://leetcode.com/problems/guess-number-higher-or-lower/) | | | +| 377 | ![M](img/M.png) [Combination Sum IV](https://leetcode.com/problems/combination-sum-iv/) | | | +| 378 | ![M](img/M.png) [Kth Smallest Element in a Sorted Matrix](https://leetcode.com/problems/kth-smallest-element-in-a-sorted-matrix/) | | | +| 383 | ![E](img/E.png) [Ransom Note](https://leetcode.com/problems/ransom-note/) | | | +| 387 | ![E](img/E.png) [First Unique Character in a String](https://leetcode.com/problems/first-unique-character-in-a-string/) | | | +| 429 | ![M](img/M.png) [N-ary Tree Level Order Traversal](https://leetcode.com/problems/n-ary-tree-level-order-traversal/) | | | +| 441 | ![E](img/E.png) [Arranging Coins](https://leetcode.com/problems/arranging-coins/) | | | +| 462 | ![M](img/M.png) [Minimum Moves to Equal Array Elements II](https://leetcode.com/problems/minimum-moves-to-equal-array-elements-ii/) | | | +| 633 | ![M](img/M.png) [Sum of Square Numbers](https://leetcode.com/problems/sum-of-square-numbers/) | | | +| 637 | ![E](img/E.png) [Average of Levels in Binary Tree](https://leetcode.com/problems/average-of-levels-in-binary-tree/) | | | +| 668 | ![H](img/H.png) [Kth Smallest Number in Multiplication Table](https://leetcode.com/problems/kth-smallest-number-in-multiplication-table/) | | | +| 695 | ![M](img/M.png) [Max Area of Island](https://leetcode.com/problems/max-area-of-island/) | | | +| 704 | ![E](img/E.png) [Binary Search](https://leetcode.com/problems/binary-search/) | | | +| 729 | ![M](img/M.png) [My Calendar I](https://leetcode.com/problems/my-calendar-i/) | | | +| 733 | ![E](img/E.png) [Flood Fill](https://leetcode.com/problems/flood-fill/) | | | +| 744 | ![E](img/E.png) [Find Smallest Letter Greater Than Target](https://leetcode.com/problems/find-smallest-letter-greater-than-target/) | | | +| 786 | ![M](img/M.png) [K-th Smallest Prime Fraction](https://leetcode.com/problems/k-th-smallest-prime-fraction/) | | | +| 804 | ![E](img/E.png) [Unique Morse Code Words](https://leetcode.com/problems/unique-morse-code-words/) | | | +| 814 | ![M](img/M.png) [Binary Tree Pruning](https://leetcode.com/problems/binary-tree-pruning/) | | | +| 852 | ![M](img/M.png) [Peak Index in a Mountain Array](https://leetcode.com/problems/peak-index-in-a-mountain-array/) | | | +| 858 | ![M](img/M.png) [Mirror Reflection](https://leetcode.com/problems/mirror-reflection/) | | | +| 867 | ![E](img/E.png) [Transpose Matrix](https://leetcode.com/problems/transpose-matrix/) | | | +| 871 | ![H](img/H.png) [Minimum Number of Refueling Stops](https://leetcode.com/problems/minimum-number-of-refueling-stops/) | | | +| 890 | ![M](img/M.png) [Find and Replace Pattern](https://leetcode.com/problems/find-and-replace-pattern/) | | | +| 967 | ![M](img/M.png) [Numbers With Same Consecutive Differences](https://leetcode.com/problems/numbers-with-same-consecutive-differences/) | | | +| 987 | ![H](img/H.png) [Vertical Order Traversal of a Binary Tree](https://leetcode.com/problems/vertical-order-traversal-of-a-binary-tree/) | | | +| 1020 | ![M](img/M.png) [Number of Enclaves](https://leetcode.com/problems/number-of-enclaves/) | | | +| 1048 | ![M](img/M.png) [Longest String Chain](https://leetcode.com/problems/longest-string-chain/) | | | +| 1175 | ![E](img/E.png) [Prime Arrangements](https://leetcode.com/problems/prime-arrangements/) | | | +| 1250 | ![H](img/H.png) [Check If It Is a Good Array](https://leetcode.com/problems/check-if-it-is-a-good-array/) | | | +| 1254 | ![M](img/M.png) [Number of Closed Islands](https://leetcode.com/problems/number-of-closed-islands/) | | | +| 1332 | ![E](img/E.png) [Remove Palindromic Subsequences](https://leetcode.com/problems/remove-palindromic-subsequences/) | | | +| 1337 | ![E](img/E.png) [The K Weakest Rows in a Matrix](https://leetcode.com/problems/the-k-weakest-rows-in-a-matrix/) | | | +| 1338 | ![M](img/M.png) [Reduce Array Size to The Half](https://leetcode.com/problems/reduce-array-size-to-the-half/) | | | +| 1346 | ![E](img/E.png) [Check If N and Its Double Exist](https://leetcode.com/problems/check-if-n-and-its-double-exist/) | | | +| 1351 | ![E](img/E.png) [Count Negative Numbers in a Sorted Matrix](https://leetcode.com/problems/count-negative-numbers-in-a-sorted-matrix/) | | | +| 1385 | ![E](img/E.png) [Find the Distance Value Between Two Arrays](https://leetcode.com/problems/find-the-distance-value-between-two-arrays/) | | | +| 1423 | ![M](img/M.png) [Maximum Points You Can Obtain from Cards](https://leetcode.com/problems/maximum-points-you-can-obtain-from-cards/) | | | +| 1447 | ![M](img/M.png) [Simplified Fractions](https://leetcode.com/problems/simplified-fractions/) | | | +| 1448 | ![M](img/M.png) [Count Good Nodes in Binary Tree](https://leetcode.com/problems/count-good-nodes-in-binary-tree/) | | | +| 1480 | ![E](img/E.png) [Running Sum of 1d Array](https://leetcode.com/problems/running-sum-of-1d-array/) | | | +| 1539 | ![E](img/E.png) [Kth Missing Positive Number](https://leetcode.com/problems/kth-missing-positive-number/) | | | +| 1608 | ![E](img/E.png) [Special Array With X Elements Greater Than or Equal X](https://leetcode.com/problems/special-array-with-x-elements-greater-than-or-equal-x/) | | | +| 1647 | ![M](img/M.png) [Minimum Deletions to Make Character Frequencies Unique](https://leetcode.com/problems/minimum-deletions-to-make-character-frequencies-unique/) | | | +| 1689 | ![M](img/M.png) [Partitioning Into Minimum Number Of Deci-Binary Numbers](https://leetcode.com/problems/partitioning-into-minimum-number-of-deci-binary-numbers/) | | | +| 1710 | ![E](img/E.png) [Maximum Units on a Truck](https://leetcode.com/problems/maximum-units-on-a-truck/) | | | +| 1855 | ![M](img/M.png) [Maximum Distance Between a Pair of Values](https://leetcode.com/problems/maximum-distance-between-a-pair-of-values/) | | | +| 2091 | ![M](img/M.png) [Removing Minimum and Maximum From Array](https://leetcode.com/problems/removing-minimum-and-maximum-from-array/) | | | +| 2183 | ![H](img/H.png) [Count Array Pairs Divisible by K](https://leetcode.com/problems/count-array-pairs-divisible-by-k/) | | | +| 2197 | ![H](img/H.png) [Replace Non-Coprime Numbers in Array](https://leetcode.com/problems/replace-non-coprime-numbers-in-array/) | | | +| 2280 | ![M](img/M.png) [Minimum Lines to Represent a Line Chart](https://leetcode.com/problems/minimum-lines-to-represent-a-line-chart/) | | | + +### Basic algorithm implementations + +#### Binary indexed tree (Fenwick tree) + +| No. | Solutions where implemented | Lang | Notes | +|:---:|-----------------------------|:----:|-------| +| 315 | Count of Smaller Numbers After Self | ![](img/sw.png) ![](img/c.png) | Tree for counting numbers less than X | + +#### Binary search + +| No. | Solutions where implemented | Lang | Notes | +|:---:|-----------------------------|:----:|-------| +| 34 | Find First and Last Position of Element in Sorted Array | ![](img/py.png) ![](img/cpp.png) | Search for leftmost and rightmost in series of equals | +| 35 | Search Insert Position | ![](img/py.png) | Search for leftmost | +| 74 | Search a 2D Matrix | ![](img/py.png) ![](img/cpp.png) | Simple search with linear indexing of 2D matrix | +| 240 | Search a 2D Matrix II | ![](img/cpp.png) | Simple search | +| 704 | Binary Search | ![](img/py.png) ![](img/sw.png) | Simple search | + +#### Greatest common divisor (GCD) + +| No. | Solutions where implemented | Lang | Notes | +|:---:|-----------------------------|:----:|-------| +| 1447 | Simplified Fractions | ![](img/cpp.png) | | +| 2280 | Minimum Lines to Represent a Line Chart | ![](img/cpp.png) | | + +#### Single-linked list + +| No. | Solutions where implemented | Lang | Notes | +|:---:|-----------------------------|:----:|-------| +| 25 | Reverse Nodes in k-Group | ![](img/py.png) | | +| 92 | Reverse Linked List II | ![](img/py.png) | | + + +### Other helpers + +| Helper | Solution | Lang | +|--------|----------|:----:| +| `Py` implementation of ListNode's `__str__` and `__repr__` | 25. Reverse Nodes in k-Group | | +| Dynamic array | 637. Average of Levels in Binary Tree | | +| `Swift` queue using single-linked list | 695. Max Area of Island | | +| Building TreeNode’s tree from array | 814. Binary Tree Pruning | | +| Building TreeNode's tree from array | 987. Vertical Order Traversal of a Binary Tree | |