Tree & Graph LeetCode Problems A collection of LeetCode problems solved using Tree & Graph pattern techniques, explanations, and complexity analysis. Problems Easy # Problem Language Time Space Explanation 112 Path Sum PHP 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 733 Flood Fill Python O(n) O(n) Explanation 1022 Sum of Root To Leaf Binary Numbers Python O(n) O(n) Explanation 1184 Distance Between Bus Stops Python O(n) O(n) Explanation 1217 Minimum Cost to Move Chips to The Same Position Python O(n) O(n) Explanation 1260 Shift 2D Grid Racket O(n) O(n) Explanation 1422 Maximum Score After Splitting a String Python O(n) O(n) Explanation 2078 Two Furthest Houses With Different Colors Python O(n) O(n) Explanation 2315 Count Asterisks Python O(n) O(n) Explanation 2335 Minimum Amount of Time to Fill Cups Python O(n) O(n) Explanation 2399 Check Distances Between Same Letters Python O(n) O(n) Explanation 2409 Count Days Spent Together Python O(n) O(n) Explanation 2667 Create Hello World Function TypeScript O(n) O(n) Explanation 2710 Remove Trailing Zeros From a String Python O(n) O(n) Explanation 2864 Maximum Odd Binary Number JavaScript O(n) O(n) Explanation 2885 Rename Columns Python O(n) O(n) Explanation 2903 Find Indices With Index and Value Difference I JavaScript O(n) O(n) Explanation 3492 Maximum Containers on a Ship Python O(n) O(n) Explanation 3769 Sort Integers by Binary Reflection JavaScript O(n) O(n) Explanation 3959 Check Good Integer Python O(n) O(n) Explanation Medium # Problem Language Time Space Explanation 6 Zigzag Conversion Python O(n) O(n) Explanation 79 Word Search JavaScript, PHP O(n) O(n) Explanation 129 Sum Root to Leaf Numbers JavaScript O(n) O(n) Explanation 164 Maximum Gap Python O(n) O(n) Explanation 337 House Robber III JavaScript O(n) O(n) Explanation 417 Pacific Atlantic Water Flow Python O(n) O(n) Explanation 529 Minesweeper Python O(n) O(n) Explanation 547 Number of Provinces JavaScript O(n) O(n) Explanation 684 Redundant Connection Python O(n) O(n) Explanation 686 Repeated String Match JavaScript O(n) O(n) Explanation 687 Longest Univalue Path Python O(n) O(n) Explanation 690 Employee Importance Python O(n) O(n) Explanation 695 Max Area of Island Python O(n) O(n) Explanation 785 Is Graph Bipartite? Python O(n) O(n) Explanation 797 All Paths From Source to Target Python O(n) O(n) Explanation 826 Most Profit Assigning Work Python O(n) O(n) Explanation 841 Keys and Rooms JavaScript O(n) O(n) Explanation 877 Stone Game C++, Python O(n) O(n) Explanation 893 Groups of Special-Equivalent Strings Python O(n) O(n) Explanation 926 Flip String to Monotone Increasing Python O(n) O(n) Explanation 959 Regions Cut By Slashes Python O(n) O(n) Explanation 994 Rotting Oranges JavaScript, Python O(n) O(n) Explanation 998 Maximum Binary Tree II Python O(n) O(n) Explanation 1219 Path with Maximum Gold Python O(n) O(n) Explanation 1267 Count Servers that Communicate Python O(n) O(n) Explanation 1306 Jump Game III C++ O(n) O(n) Explanation 1339 Maximum Product of Splitted Binary Tree Python O(n) O(n) Explanation 1358 Number of Substrings Containing All Three Characters Java, Python O(n) O(n) Explanation 1387 Sort Integers by The Power Value Python O(n) O(n) Explanation 1461 Check If a String Contains All Binary Codes of Size K Python O(n) O(n) Explanation 1466 Reorder Routes to Make All Paths Lead to the City Zero JavaScript O(n) O(n) Explanation 1578 Minimum Time to Make Rope Colorful Python O(n) O(n) Explanation 1594 Maximum Non Negative Product in a Matrix Python O(n) O(n) Explanation 1599 Maximum Profit of Operating a Centennial Wheel Python O(n) O(n) Explanation 1718 Construct the Lexicographically Largest Valid Sequence Python O(n) O(n) Explanation 1774 Closest Dessert Cost Python O(n) O(n) Explanation 1792 Maximum Average Pass Ratio Python O(n) O(n) Explanation 1849 Splitting a String Into Descending Consecutive Values Python O(n) O(n) Explanation 1870 Minimum Speed to Arrive on Time Python O(n) O(n) Explanation 1914 Cyclically Rotating a Grid C++ O(n) O(n) Explanation 1954 Minimum Garden Perimeter to Collect Enough Apples Python O(n) O(n) Explanation 2029 Stone Game IX C++ O(n) O(n) Explanation 2044 Count Number of Maximum Bitwise-OR Subsets Python O(n) O(n) Explanation 2064 Minimized Maximum of Products Distributed to Any Store Python O(n) O(n) Explanation 2161 Partition Array According to Given Pivot Java O(n) O(n) Explanation 2165 Smallest Value of the Rearranged Number JavaScript O(n) O(n) Explanation 2245 Maximum Trailing Zeros in a Cornered Path Python O(n) O(n) Explanation 2279 Maximum Bags With Full Capacity of Rocks Python O(n) O(n) Explanation 2305 Fair Distribution of Cookies Python O(n) O(n) Explanation 2391 Minimum Amount of Time to Collect Garbage JavaScript O(n) O(n) Explanation 2410 Maximum Matching of Players With Trainers Python O(n) O(n) Explanation 2428 Maximum Sum of an Hourglass Python O(n) O(n) Explanation 2471 Minimum Number of Operations to Sort a Binary Tree by Level Python O(n) O(n) Explanation 2492 Minimum Score of a Path Between Two Cities Java, Python O(n) O(n) Explanation 2517 Maximum Tastiness of Candy Basket Python O(n) O(n) Explanation 2530 Maximal Score After Applying K Operations Python O(n) O(n) Explanation 2560 House Robber IV Python O(n) O(n) Explanation 2567 Minimum Score by Changing Two Elements Python O(n) O(n) Explanation 2594 Minimum Time to Repair Cars Python O(n) O(n) Explanation 2624 Snail Traversal TypeScript O(n) O(n) Explanation 2658 Maximum Number of Fish in a Grid Python O(n) O(n) Explanation 2680 Maximum OR Python O(n) O(n) Explanation 2694 Event Emitter TypeScript O(n) O(n) Explanation 2740 Find the Value of the Partition JavaScript O(n) O(n) Explanation 2850 Minimum Moves to Spread Stones Over Grid Python O(n) O(n) Explanation 2856 Minimum Array Length After Pair Removals Python O(n) O(n) Explanation 2895 Minimum Processing Time JavaScript O(n) O(n) Explanation 2905 Find Indices With Index and Value Difference II JavaScript O(n) O(n) Explanation 2952 Minimum Number of Coins to be Added JavaScript O(n) O(n) Explanation 2971 Find Polygon With the Largest Perimeter JavaScript O(n) O(n) Explanation 3002 Maximum Size of a Set After Removals JavaScript O(n) O(n) Explanation 3025 Find the Number of Ways to Place People I Python O(n) O(n) Explanation 3047 Find the Largest Area of Square Inside Two Rectangles Python O(n) O(n) Explanation 3071 Minimum Operations to Write the Letter Y on a Grid Python O(n) O(n) Explanation 3148 Maximum Difference Score in a Grid Python O(n) O(n) Explanation 3175 Find The First Player to win K Games in a Row JavaScript O(n) O(n) Explanation 3211 Generate Binary Strings Without Adjacent Zeros Python O(n) O(n) Explanation 3239 Minimum Number of Flips to Make Binary Grid Palindromic I Python O(n) O(n) Explanation 3240 Minimum Number of Flips to Make Binary Grid Palindromic II Python O(n) O(n) Explanation 3243 Shortest Distance After Road Addition Queries I JavaScript O(n) O(n) Explanation 3301 Maximize the Total Height of Unique Towers JavaScript O(n) O(n) Explanation 3309 Maximum Possible Number by Binary Concatenation Python O(n) O(n) Explanation 3537 Fill a Special Grid Python O(n) O(n) Explanation 3567 Minimum Absolute Difference in Sliding Submatrix Python O(n) O(n) Explanation 3608 Minimum Time for K Connected Components Python O(n) O(n) Explanation 3639 Minimum Time to Activate String Python O(n) O(n) Explanation 3733 Minimum Time to Complete All Deliveries Python O(n) O(n) Explanation 3789 Minimum Cost to Acquire Required Items Python O(n) O(n) Explanation 3796 Find Maximum Value in a Constrained Sequence JavaScript O(n) O(n) Explanation 3863 Minimum Operations to Sort a String Python O(n) O(n) Explanation 3938 Maximum Path Intersection Sum in a Grid Python O(n) O(n) Explanation 4008 Minimum Initial Strength to Defeat All Monsters Python O(n) O(n) Explanation Hard # Problem Language Time Space Explanation 282 Expression Add Operators Python O(n) O(n) Explanation 761 Special Binary String Python O(n) O(n) Explanation 987 Vertical Order Traversal of a Binary Tree Python O(n) O(n) Explanation 996 Number of Squareful Arrays JavaScript O(n) O(n) Explanation 1192 Critical Connections in a Network JavaScript O(n) O(n) Explanation 1377 Frog Position After T Seconds JavaScript O(n) O(n) Explanation 1383 Maximum Performance of a Team Python O(n) O(n) Explanation 1505 Minimum Possible Integer After at Most K Adjacent Swaps On Digits JavaScript O(n) O(n) Explanation 1601 Maximum Number of Achievable Transfer Requests Python O(n) O(n) Explanation 1923 Longest Common Subpath Python O(n) O(n) Explanation 2136 Earliest Possible Day of Full Bloom Python O(n) O(n) Explanation 2141 Maximum Running Time of N Computers Python O(n) O(n) Explanation 2167 Minimum Time to Remove All Cars Containing Illegal Goods Python O(n) O(n) Explanation 2953 Count Complete Substrings Python O(n) O(n) Explanation 3003 Maximize the Number of Partitions After Operations Python O(n) O(n) Explanation 3027 Find the Number of Ways to Place People II Python O(n) O(n) Explanation 3102 Minimize Manhattan Distances Python O(n) O(n) Explanation 3449 Maximize the Minimum Game Score Python O(n) O(n) Explanation 3677 Count Binary Palindromic Numbers Python O(n) O(n) Explanation 3864 Minimum Cost to Partition a Binary String Python O(n) O(n) Explanation 3897 Maximum Value of Concatenated Binary Segments JavaScript O(n) O(n) Explanation 4105 Repeated String Match II JavaScript O(n) O(n) Explanation