A collection of LeetCode problems solved using Tree & Graph pattern techniques, explanations, and complexity analysis.
| # | Problem | Language | Time | Space | Explanation |
|---|---|---|---|---|---|
| 67 | Add Binary | Python | O(n) | O(n) | Explanation |
| 94 | Binary Tree Inorder Traversal | PHP | O(n) | O(n) | Explanation |
| 100 | Same Tree | PHP | O(n) | O(n) | Explanation |
| 101 | Symmetric Tree | PHP | O(n) | O(n) | Explanation |
| 112 | Path Sum | PHP | O(n) | O(n) | Explanation |
| 144 | Binary Tree Preorder Traversal | PHP | O(n) | O(n) | Explanation |
| 145 | Binary Tree Postorder Traversal | PHP | O(n) | O(n) | Explanation |
| 401 | Binary Watch | Python | O(n) | O(n) | Explanation |
| 404 | Sum of Left Leaves | Python | O(n) | O(n) | Explanation |
| 559 | Maximum Depth of N-ary Tree | Python | O(n) | O(n) | Explanation |
| 566 | Reshape the Matrix | Python | O(n) | O(n) | Explanation |
| 572 | Subtree of Another Tree | Python | O(n) | O(n) | Explanation |
| 589 | N-ary Tree Preorder Traversal | Python | O(n) | O(n) | Explanation |
| 590 | N-ary Tree Postorder Traversal | Python | O(n) | O(n) | Explanation |
| 617 | Merge Two Binary Trees | Python | O(n) | O(n) | Explanation |
| 696 | Count Binary Substrings | Python | O(n) | O(n) | Explanation |
| 766 | Toeplitz Matrix | Python | O(n) | O(n) | Explanation |
| 867 | Transpose Matrix | Python | O(n) | O(n) | Explanation |
| 868 | Binary Gap | Python | O(n) | O(n) | Explanation |
| 872 | Leaf-Similar Trees | Python | O(n) | O(n) | Explanation |
| 1022 | Sum of Root To Leaf Binary Numbers | Python | O(n) | O(n) | Explanation |
| 1030 | Matrix Cells in Distance Order | Python | O(n) | O(n) | Explanation |
| 1160 | Find Words That Can Be Formed by Characters | Python | O(n) | O(n) | Explanation |
| 1252 | Cells with Odd Values in a Matrix | Python | O(n) | O(n) | Explanation |
| 1260 | Shift 2D Grid | Racket | O(n) | O(n) | Explanation |
| 1337 | The K Weakest Rows in a Matrix | Python | O(n) | O(n) | Explanation |
| 1351 | Count Negative Numbers in a Sorted Matrix | Python | O(n) | O(n) | Explanation |
| 1380 | Lucky Numbers in a Matrix | Python | O(n) | O(n) | Explanation |
| 1496 | Path Crossing | Python | O(n) | O(n) | Explanation |
| 1572 | Matrix Diagonal Sum | Python | O(n) | O(n) | Explanation |
| 1710 | Maximum Units on a Truck | C++ | O(n) | O(n) | Explanation |
| 1758 | Minimum Changes To Make Alternating Binary String | C++ | O(n) | O(n) | Explanation |
| 1779 | Find Nearest Point That Has the Same X or Y Coordinate | C++ | O(n) | O(n) | Explanation |
| 1854 | Maximum Population Year | C++ | O(n) | O(n) | Explanation |
| 1886 | Determine Whether Matrix Can Be Obtained By Rotation | C++ | O(n) | O(n) | Explanation |
| 1967 | Number of Strings That Appear as Substrings in Word | Kotlin | O(n) | O(n) | Explanation |
| 2667 | Create Hello World Function | TypeScript | O(n) | O(n) | Explanation |
| 2884 | Modify Columns | Python | O(n) | O(n) | Explanation |
| 2885 | Rename Columns | Python | O(n) | O(n) | Explanation |
| 2889 | Reshape Data: Pivot | Python | O(n) | O(n) | Explanation |
| 3345 | Smallest Divisible Digit Product I | Ruby | O(n) | O(n) | Explanation |
| 3870 | Count Commas in Range | JavaScript | O(n) | O(n) | Explanation |
| 3903 | Smallest Stable Index I | JavaScript | O(n) | O(n) | Explanation |
| # | Problem | Language | Time | Space | Explanation |
|---|---|---|---|---|---|
| 38 | Count and Say | Python | O(n) | O(n) | Explanation |
| 50 | Pow(x, n) | Python | O(n) | O(n) | Explanation |
| 53 | Maximum Subarray | Python | O(n) | O(n) | Explanation |
| 54 | Spiral Matrix | Python | O(n) | O(n) | Explanation |
| 59 | Spiral Matrix II | Python | O(n) | O(n) | Explanation |
| 62 | Unique Paths | Python | O(n) | O(n) | Explanation |
| 63 | Unique Paths II | Python | O(n) | O(n) | Explanation |
| 64 | Minimum Path Sum | Python | O(n) | O(n) | Explanation |
| 71 | Simplify Path | Python | O(n) | O(n) | Explanation |
| 73 | Set Matrix Zeroes | JavaScript | O(n) | O(n) | Explanation |
| 74 | Search a 2D Matrix | Python | O(n) | O(n) | Explanation |
| 550 | Game Play Analysis IV | Python | O(n) | O(n) | Explanation |
| 877 | Stone Game | C++ | O(n) | O(n) | Explanation |
| 1306 | Jump Game III | C++ | O(n) | O(n) | Explanation |
| 1358 | Number of Substrings Containing All Three Characters | Java | O(n) | O(n) | Explanation |
| 1914 | Cyclically Rotating a Grid | C++ | O(n) | O(n) | Explanation |
| 2029 | Stone Game IX | C++ | O(n) | O(n) | Explanation |
| 2161 | Partition Array According to Given Pivot | Java | O(n) | O(n) | Explanation |
| 2492 | Minimum Score of a Path Between Two Cities | Java | O(n) | O(n) | Explanation |
| 2624 | Snail Traversal | TypeScript | O(n) | O(n) | Explanation |
| 2685 | Count the Number of Complete Components | Java | O(n) | O(n) | Explanation |
| 2812 | Find the Safest Path in a Grid | Java | O(n) | O(n) | Explanation |
| 3286 | Find a Safe Walk Through a Grid | Java | O(n) | O(n) | Explanation |
| 3310 | Remove Methods From Project | C++ | O(n) | O(n) | Explanation |
| 3513 | Number of Unique XOR Triplets I | C++ | O(n) | O(n) | Explanation |
| 3514 | Number of Unique XOR Triplets II | C++ | O(n) | O(n) | Explanation |
| 3517 | Smallest Palindromic Rearrangement I | C++ | O(n) | O(n) | Explanation |
| 3532 | Path Existence Queries in a Graph I | Java | O(n) | O(n) | Explanation |
| 3558 | Number of Ways to Assign Edge Weights I | Java | O(n) | O(n) | Explanation |
| 3612 | Process String with Special Operations I | Java | O(n) | O(n) | Explanation |
| 3742 | Maximum Path Score in a Grid | C++ | O(n) | O(n) | Explanation |
| # | Problem | Language | Time | Space | Explanation |
|---|---|---|---|---|---|
| 51 | N-Queens | Python | O(n) | O(n) | Explanation |
| 1840 | Maximum Building Height | Python | O(n) | O(n) | Explanation |
| 3518 | Smallest Palindromic Rearrangement II | PHP | O(n) | O(n) | Explanation |
| 3534 | Path Existence Queries in a Graph II | PHP | O(n) | O(n) | Explanation |
| 3559 | Number of Ways to Assign Edge Weights II | Python | O(n) | O(n) | Explanation |
| 3614 | Process String with Special Operations II | Python | O(n) | O(n) | Explanation |
| 3620 | Network Recovery Pathways | PHP | O(n) | O(n) | Explanation |
| 3700 | Number of ZigZag Arrays II | PHP | O(n) | O(n) | Explanation |