Binary Search LeetCode Problems A collection of LeetCode problems solved using Binary Search pattern techniques, explanations, and complexity analysis. Problems Easy # Problem Language Time Space Explanation 35 Search Insert Position JavaScript, Python O(log n) O(1) Explanation 67 Add Binary Python O(n) O(1) Explanation 94 Binary Tree Inorder Traversal JavaScript, PHP O(n) O(1) Explanation 100 Same Tree PHP O(n) O(1) Explanation 101 Symmetric Tree JavaScript, PHP O(n) O(1) Explanation 104 Maximum Depth of Binary Tree JavaScript, PHP O(n) O(1) Explanation 108 Convert Sorted Array to Binary Search Tree JavaScript, PHP O(n) O(1) Explanation 110 Balanced Binary Tree PHP O(n) O(1) Explanation 111 Minimum Depth of Binary Tree PHP O(n) O(1) Explanation 226 Invert Binary Tree JavaScript, PHP O(n) O(1) Explanation 257 Binary Tree Paths PHP O(n) O(1) Explanation 338 Counting Bits C++, JavaScript O(n) O(1) Explanation 401 Binary Watch Python O(n) O(1) Explanation 501 Find Mode in Binary Search Tree Python O(n) O(1) Explanation 530 Minimum Absolute Difference in BST Python O(n) O(1) Explanation 543 Diameter of Binary Tree JavaScript, Python O(n) O(1) Explanation 563 Binary Tree Tilt Python O(n) O(1) Explanation 572 Subtree of Another Tree Python O(n) O(1) Explanation 617 Merge Two Binary Trees Python O(n) O(1) Explanation 628 Maximum Product of Three Numbers Elixir O(n) O(1) Explanation 637 Average of Levels in Binary Tree Python O(n) O(1) Explanation 653 Two Sum IV - Input is a BST Python O(n) O(1) Explanation 700 Search in a Binary Search Tree JavaScript, Python O(n) O(1) Explanation 704 Binary Search Python O(log n) O(1) Explanation 783 Minimum Distance Between BST Nodes Python O(n) O(1) Explanation 804 Unique Morse Code Words Python O(n) O(1) Explanation 819 Most Common Word Python O(n) O(1) Explanation 868 Binary Gap Python O(n) O(1) Explanation 872 Leaf-Similar Trees JavaScript, Python O(n) O(1) Explanation 897 Increasing Order Search Tree Python O(n) O(1) Explanation 929 Unique Email Addresses Python O(n) O(1) Explanation 938 Range Sum of BST Python O(n) O(1) Explanation 965 Univalued Binary Tree Python O(n) O(1) Explanation 993 Cousins in Binary Tree Python O(n) O(1) Explanation 1290 Convert Binary Number in a Linked List to Integer Python O(n) O(1) Explanation 1331 Rank Transform of an Array Kotlin O(n) O(1) Explanation 1379 Find a Corresponding Node of a Binary Tree in a Clone of That Tree Python O(n) O(1) Explanation 1464 Maximum Product of Two Elements in an Array Scala O(n) O(1) Explanation 1752 Check if Array Is Sorted and Rotated C++ O(n) O(1) Explanation 2022 Convert 1D Array Into 2D Array Python O(n) O(1) Explanation 2331 Evaluate Boolean Binary Tree JavaScript O(n) O(1) Explanation 2427 Number of Common Factors Python O(n) O(1) Explanation 2529 Maximum Count of Positive Integer and Negative Integer Python O(n) O(1) Explanation 3069 Distribute Elements Into Two Arrays I Go O(n) O(1) Explanation 3477 Fruits Into Baskets II JavaScript O(n) O(1) Explanation 3875 Construct Uniform Parity Array I C++ O(n) O(1) Explanation Medium # Problem Language Time Space Explanation 15 3Sum JavaScript O(log n) O(1) Explanation 16 3Sum Closest JavaScript, Python O(log n) O(1) Explanation 18 4Sum C++ O(log n) O(1) Explanation 33 Search in Rotated Sorted Array C++, JavaScript, Python O(log n) O(1) Explanation 34 Find First and Last Position of Element in Sorted Array JavaScript, Python O(log n) O(1) Explanation 62 Unique Paths JavaScript, Python O(n) O(1) Explanation 63 Unique Paths II Python O(n) O(1) Explanation 81 Search in Rotated Sorted Array II PHP O(n) O(1) Explanation 95 Unique Binary Search Trees II JavaScript O(n) O(1) Explanation 96 Unique Binary Search Trees JavaScript O(n) O(1) Explanation 98 Validate Binary Search Tree JavaScript O(n) O(1) Explanation 99 Recover Binary Search Tree JavaScript O(n) O(1) Explanation 105 Construct Binary Tree from Preorder and Inorder Traversal JavaScript O(n) O(1) Explanation 106 Construct Binary Tree from Inorder and Postorder Traversal JavaScript, Python O(n) O(1) Explanation 109 Convert Sorted List to Binary Search Tree Python O(n) O(1) Explanation 114 Flatten Binary Tree to Linked List JavaScript O(n) O(1) Explanation 153 Find Minimum in Rotated Sorted Array C++, JavaScript O(log n) O(1) Explanation 162 Find Peak Element JavaScript O(log n) O(1) Explanation 173 Binary Search Tree Iterator JavaScript O(n) O(1) Explanation 199 Binary Tree Right Side View JavaScript O(n) O(1) Explanation 209 Minimum Size Subarray Sum JavaScript O(n) O(1) Explanation 230 Kth Smallest Element in a BST JavaScript O(n) O(1) Explanation 235 Lowest Common Ancestor of a Binary Search Tree JavaScript O(n) O(1) Explanation 236 Lowest Common Ancestor of a Binary Tree JavaScript O(n) O(1) Explanation 284 Peeking Iterator JavaScript O(n) O(1) Explanation 300 Longest Increasing Subsequence JavaScript O(n) O(1) Explanation 310 Minimum Height Trees JavaScript O(n) O(1) Explanation 347 Top K Frequent Elements Python O(n log n) O(1) Explanation 449 Serialize and Deserialize BST Python O(n) O(1) Explanation 450 Delete Node in a BST JavaScript, Python O(n) O(1) Explanation 468 Validate IP Address Python O(n) O(1) Explanation 513 Find Bottom Left Tree Value Python O(n) O(1) Explanation 538 Convert BST to Greater Tree Python O(n) O(1) Explanation 540 Single Element in a Sorted Array JavaScript O(log n) O(1) Explanation 558 Logical OR of Two Binary Grids Represented as Quad-Trees Python O(n) O(1) Explanation 623 Add One Row to Tree Python O(n) O(1) Explanation 655 Print Binary Tree Python O(n) O(1) Explanation 669 Trim a Binary Search Tree Python O(n) O(1) Explanation 701 Insert into a Binary Search Tree Python O(n) O(1) Explanation 788 Rotated Digits C++ O(n) O(1) Explanation 814 Binary Tree Pruning Python O(n) O(1) Explanation 823 Binary Trees With Factors Python O(n) O(1) Explanation 852 Peak Index in a Mountain Array JavaScript, Python O(n) O(1) Explanation 863 All Nodes Distance K in Binary Tree Python O(n) O(1) Explanation 889 Construct Binary Tree from Preorder and Postorder Traversal Python O(n) O(1) Explanation 894 All Possible Full Binary Trees Python O(n) O(1) Explanation 900 RLE Iterator JavaScript O(n) O(1) Explanation 904 Fruit Into Baskets Python O(n) O(1) Explanation 912 Sort an Array Python O(n) O(1) Explanation 919 Complete Binary Tree Inserter Python O(n) O(1) Explanation 930 Binary Subarrays With Sum Python O(n) O(1) Explanation 946 Validate Stack Sequences JavaScript O(n) O(1) Explanation 951 Flip Equivalent Binary Trees Python O(n) O(1) Explanation 958 Check Completeness of a Binary Tree Python O(n) O(1) Explanation 979 Distribute Coins in Binary Tree Python O(n) O(1) Explanation 1008 Construct Binary Search Tree from Preorder Traversal Python O(n) O(1) Explanation 1038 Binary Search Tree to Greater Sum Tree Python O(n) O(1) Explanation 1123 Lowest Common Ancestor of Deepest Leaves JavaScript O(n) O(1) Explanation 1145 Binary Tree Coloring Game JavaScript O(n) O(1) Explanation 1161 Maximum Level Sum of a Binary Tree JavaScript O(n) O(1) Explanation 1261 Find Elements in a Contaminated Binary Tree Python O(n) O(1) Explanation 1288 Remove Covered Intervals Java O(log n) O(1) Explanation 1305 All Elements in Two Binary Search Trees Python O(n) O(1) Explanation 1361 Validate Binary Tree Nodes Python O(n) O(1) Explanation 1367 Linked List in Binary Tree JavaScript O(n) O(1) Explanation 1372 Longest ZigZag Path in a Binary Tree JavaScript O(n) O(1) Explanation 1382 Balance a Binary Search Tree Python O(n) O(1) Explanation 1448 Count Good Nodes in Binary Tree JavaScript O(n) O(1) Explanation 1487 Making File Names Unique Python O(n) O(1) Explanation 1545 Find Kth Bit in Nth Binary String Python O(n) O(1) Explanation 1833 Maximum Ice Cream Bars Java O(n) O(1) Explanation 1846 Maximum Element After Decreasing and Rearranging Java O(log n) O(1) Explanation 1901 Find a Peak Element II Python O(n) O(1) Explanation 1980 Find Unique Binary String Python O(n) O(1) Explanation 1993 Operations on Tree Python O(n) O(1) Explanation 2196 Create Binary Tree From Descriptions Java, Python O(n) O(1) Explanation 2250 Count Number of Rectangles Containing Each Point JavaScript O(n) O(1) Explanation 2359 Find Closest Node to Given Two Nodes JavaScript O(n) O(1) Explanation 2385 Amount of Time for Binary Tree to Be Infected Python O(n) O(1) Explanation 2415 Reverse Odd Levels of Binary Tree Python O(n) O(1) Explanation 2476 Closest Nodes Queries in a Binary Search Tree Python O(n) O(1) Explanation 2583 Kth Largest Sum in a Binary Tree Python O(n) O(1) Explanation 2641 Cousins in Binary Tree II Python O(n) O(1) Explanation 3479 Fruits Into Baskets III Python O(n) O(1) Explanation 3488 Closest Equal Element Queries Python O(n) O(1) Explanation 3514 Number of Unique XOR Triplets II C++ O(n) O(1) Explanation 3524 Find X Value of Array I JavaScript O(n) O(1) Explanation 3679 Minimum Discards to Balance Inventory Python O(n) O(1) Explanation 3689 Maximum Total Subarray Value I Java O(n) O(1) Explanation 3960 Frequency Balance Subarray JavaScript O(n) O(1) Explanation 4021 Minimum Operations to Make a Rotated Palindrome I Python O(n) O(1) Explanation 4099 Minimum Operations to Sort With Locked Indices JavaScript O(n) O(1) Explanation Hard # Problem Language Time Space Explanation 4 Median of Two Sorted Arrays JavaScript, Python O(n) O(1) Explanation 124 Binary Tree Maximum Path Sum JavaScript O(n) O(1) Explanation 154 Find Minimum in Rotated Sorted Array II C++ O(n) O(1) Explanation 212 Word Search II JavaScript O(n) O(1) Explanation 297 Serialize and Deserialize Binary Tree Python O(n) O(1) Explanation 675 Cut Off Trees for Golf Event Python O(n) O(1) Explanation 834 Sum of Distances in Tree JavaScript O(n) O(1) Explanation 952 Largest Component Size by Common Factor Python O(n) O(1) Explanation 968 Binary Tree Cameras Python O(n) O(1) Explanation 980 Unique Paths III JavaScript O(n) O(1) Explanation 1028 Recover a Tree From Preorder Traversal JavaScript O(n) O(1) Explanation 1092 Shortest Common Supersequence Python O(n) O(1) Explanation 1206 Design Skiplist JavaScript O(n) O(1) Explanation 1373 Maximum Sum BST in Binary Tree Python O(n) O(1) Explanation 1483 Kth Ancestor of a Tree Node JavaScript O(n) O(1) Explanation 1489 Find Critical and Pseudo-Critical Edges in Minimum Spanning Tree Python O(n) O(1) Explanation 1569 Number of Ways to Reorder Array to Get Same BST Python O(n) O(1) Explanation 1665 Minimum Initial Energy to Finish Tasks C++ O(log n) O(1) Explanation 1755 Closest Subsequence Sum JavaScript O(n) O(1) Explanation 1766 Tree of Coprimes Python O(n) O(1) Explanation 1932 Merge BSTs to Create Single BST Python O(n) O(1) Explanation 2122 Recover the Original Array Python O(n) O(1) Explanation 2213 Longest Substring of One Repeating Character Java O(n) O(1) Explanation 2458 Height of Binary Tree After Subtree Removal Queries Python O(n) O(1) Explanation 2846 Minimum Edge Weight Equilibrium Queries in a Tree Python O(n) O(1) Explanation 3072 Distribute Elements Into Two Arrays II JavaScript O(n) O(1) Explanation 3525 Find X Value of Array II JavaScript O(n) O(1) Explanation 3585 Find Weighted Median Node in Tree Python O(n) O(1) Explanation 3600 Maximize Spanning Tree Stability with Upgrades JavaScript O(n) O(1) Explanation 3605 Minimum Stability Factor of Array JavaScript O(n) O(1) Explanation 3620 Network Recovery Pathways PHP O(n) O(1) Explanation 3841 Palindromic Path Queries in a Tree JavaScript, Python O(n) O(1) Explanation 3924 Minimum Threshold Path With Limited Heavy Edges JavaScript O(n) O(1) Explanation