Skip to content
LEETFLIX

method

Binary Search — animated LeetCode walkthroughs

LeetCode problems solved with Binary Search. Browse the complete tag, then watch the algorithm move — step-by-step animation, Python and Go.

352 problems · 302 animated · 50 locked

Full Binary search index

  1. 4Median of Two Sorted ArraysWatch
  2. 33Search in Rotated Sorted ArrayWatch
  3. 34Find First and Last Position of Element in Sorted ArrayWatch
  4. 35Search Insert PositionWatch
  5. 69Sqrt(x)Watch
  6. 74Search a 2D MatrixWatch
  7. 81Search in Rotated Sorted Array IIWatch
  8. 153Find Minimum in Rotated Sorted ArrayWatch
  9. 154Find Minimum in Rotated Sorted Array IIWatch
  10. 162Find Peak ElementWatch
  11. 167Two Sum II - Input Array Is SortedWatch
  12. 209Minimum Size Subarray SumWatch
  13. 222Count Complete Tree NodesWatch
  14. 240Search a 2D Matrix IIWatch
  15. 2593Sum SmallerLocked
  16. 268Missing NumberWatch
  17. 270Closest Binary Search Tree ValueLocked
  18. 275H-Index IIWatch
  19. 278First Bad VersionWatch
  20. 287Find the Duplicate NumberWatch
  21. 300Longest Increasing SubsequenceWatch
  22. 302Smallest Rectangle Enclosing Black PixelsLocked
  23. 315Count of Smaller Numbers After SelfWatch
  24. 327Count of Range SumWatch
  25. 349Intersection of Two ArraysWatch
  26. 350Intersection of Two Arrays IIWatch
  27. 352Data Stream as Disjoint IntervalsWatch
  28. 354Russian Doll EnvelopesWatch
  29. 362Design Hit CounterLocked
  30. 363Max Sum of Rectangle No Larger Than KWatch
  31. 367Valid Perfect SquareWatch
  32. 374Guess Number Higher or LowerWatch
  33. 378Kth Smallest Element in a Sorted MatrixWatch
  34. 400Nth DigitWatch
  35. 410Split Array Largest SumWatch
  36. 436Find Right IntervalWatch
  37. 441Arranging CoinsWatch
  38. 456132 PatternWatch
  39. 475HeatersWatch
  40. 483Smallest Good BaseWatch
  41. 493Reverse PairsWatch
  42. 497Random Point in Non-overlapping RectanglesWatch
  43. 528Random Pick with WeightWatch
  44. 532K-diff Pairs in an ArrayWatch
  45. 540Single Element in a Sorted ArrayWatch
  46. 611Valid Triangle NumberWatch
  47. 633Sum of Square NumbersWatch
  48. 644Maximum Average Subarray IILocked
  49. 658Find K Closest ElementsWatch
  50. 668Kth Smallest Number in Multiplication TableWatch
  51. 702Search in a Sorted Array of Unknown SizeLocked
  52. 704Binary SearchWatch
  53. 710Random Pick with BlacklistWatch
  54. 713Subarray Product Less Than KWatch
  55. 718Maximum Length of Repeated SubarrayWatch
  56. 719Find K-th Smallest Pair DistanceWatch
  57. 729My Calendar IWatch
  58. 731My Calendar IIWatch
  59. 732My Calendar IIIWatch
  60. 744Find Smallest Letter Greater Than TargetWatch
  61. 754Reach a NumberWatch
  62. 774Minimize Max Distance to Gas StationLocked
  63. 778Swim in Rising WaterWatch
  64. 786K-th Smallest Prime FractionWatch
  65. 792Number of Matching SubsequencesWatch
  66. 793Preimage Size of Factorial Zeroes FunctionWatch
  67. 825Friends Of Appropriate AgesWatch
  68. 826Most Profit Assigning WorkWatch
  69. 852Peak Index in a Mountain ArrayWatch
  70. 862Shortest Subarray with Sum at Least KWatch
  71. 875Koko Eating BananasWatch
  72. 878Nth Magical NumberWatch
  73. 887Super Egg DropWatch
  74. 888Fair Candy SwapWatch
  75. 902Numbers At Most N Given Digit SetWatch
  76. 911Online ElectionWatch
  77. 981Time Based Key-Value StoreWatch
  78. 1004Max Consecutive Ones IIIWatch
  79. 1011Capacity To Ship Packages Within D DaysWatch
  80. 1027Longest Arithmetic SubsequenceWatch
  81. 1044Longest Duplicate SubstringWatch
  82. 1055Shortest Way to Form StringLocked
  83. 1060Missing Element in Sorted ArrayLocked
  84. 1062Longest Repeating SubstringLocked
  85. 1064Fixed PointLocked
  86. 1095Find in Mountain ArrayWatch
  87. 1099Two Sum Less Than KLocked
  88. 1102Path With Maximum Minimum ValueLocked
  89. 1146Snapshot ArrayWatch
  90. 1150Check If a Number Is Majority Element in a Sorted ArrayLocked
  91. 1157Online Majority Element In SubarrayWatch
  92. 1170Compare Strings by Frequency of the Smallest CharacterWatch
  93. 1182Shortest Distance to Target ColorLocked
  94. 1187Make Array Strictly IncreasingWatch
  95. 1198Find Smallest Common Element in All RowsLocked
  96. 1201Ugly Number IIIWatch
  97. 1208Get Equal Substrings Within BudgetWatch
  98. 1213Intersection of Three Sorted ArraysLocked
  99. 1214Two Sum BSTsLocked
  100. 1231Divide ChocolateLocked
  101. 1235Maximum Profit in Job SchedulingWatch
  102. 1237Find Positive Integer Solution for a Given EquationWatch
  103. 1268Search Suggestions SystemWatch
  104. 1283Find the Smallest Divisor Given a ThresholdWatch
  105. 1292Maximum Side Length of a Square with Sum Less than or Equal to ThresholdWatch
  106. 1300Sum of Mutated Array Closest to TargetWatch
  107. 1337The K Weakest Rows in a MatrixWatch
  108. 1346Check If N and Its Double ExistWatch
  109. 1348Tweet Counts Per FrequencyWatch
  110. 1351Count Negative Numbers in a Sorted MatrixWatch
  111. 1385Find the Distance Value Between Two ArraysWatch
  112. 1428Leftmost Column with at Least a OneLocked
  113. 1439Find the Kth Smallest Sum of a Matrix With Sorted RowsWatch
  114. 1477Find Two Non-overlapping Sub-arrays Each With Target SumWatch
  115. 1482Minimum Number of Days to Make m BouquetsWatch
  116. 1483Kth Ancestor of a Tree NodeWatch
  117. 1488Avoid Flood in The CityWatch
  118. 1498Number of Subsequences That Satisfy the Given Sum ConditionWatch
  119. 1508Range Sum of Sorted Subarray SumsWatch
  120. 1521Find a Value of a Mysterious Function Closest to TargetWatch
  121. 1533Find the Index of the Large IntegerLocked
  122. 1539Kth Missing Positive NumberWatch
  123. 1552Magnetic Force Between Two BallsWatch
  124. 1562Find Latest Group of Size MWatch
  125. 1574Shortest Subarray to be Removed to Make Array SortedWatch
  126. 1608Special Array With X Elements Greater Than or Equal XWatch
  127. 1618Maximum Font to Fit a Sentence in a ScreenLocked
  128. 1631Path With Minimum EffortWatch
  129. 1648Sell Diminishing-Valued Colored BallsWatch
  130. 1649Create Sorted Array through InstructionsWatch
  131. 1658Minimum Operations to Reduce X to ZeroWatch
  132. 1671Minimum Number of Removals to Make Mountain ArrayWatch
  133. 1712Ways to Split Array Into Three SubarraysWatch
  134. 1713Minimum Operations to Make a SubsequenceWatch
  135. 1739Building BoxesWatch
  136. 1751Maximum Number of Events That Can Be Attended IIWatch
  137. 1760Minimum Limit of Balls in a BagWatch
  138. 1782Count Pairs Of NodesWatch
  139. 1793Maximum Score of a Good SubarrayWatch
  140. 1802Maximum Value at a Given Index in a Bounded ArrayWatch
  141. 1818Minimum Absolute Sum DifferenceWatch
  142. 1838Frequency of the Most Frequent ElementWatch
  143. 1847Closest RoomWatch
  144. 1851Minimum Interval to Include Each QueryWatch
  145. 1855Maximum Distance Between a Pair of ValuesWatch
  146. 1862Sum of Floored PairsWatch
  147. 1870Minimum Speed to Arrive on TimeWatch
  148. 1885Count Pairs in Two ArraysLocked
  149. 1889Minimum Space Wasted From PackagingWatch
  150. 1891Cutting RibbonsLocked
  151. 1894Find the Student that Will Replace the ChalkWatch
  152. 1898Maximum Number of Removable CharactersWatch
  153. 1901Find a Peak Element IIWatch
  154. 1918Kth Smallest Subarray SumLocked
  155. 1923Longest Common SubpathWatch
  156. 1954Minimum Garden Perimeter to Collect Enough ApplesWatch
  157. 1956Minimum Time For K Virus Variants to SpreadLocked
  158. 1964Find the Longest Valid Obstacle Course at Each PositionWatch
  159. 1966Binary Searchable Numbers in an Unsorted ArrayLocked
  160. 1970Last Day Where You Can Still CrossWatch
  161. 2008Maximum Earnings From TaxiWatch
  162. 2009Minimum Number of Operations to Make Array ContinuousWatch
  163. 2024Maximize the Confusion of an ExamWatch
  164. 2031Count Subarrays With More Ones Than ZerosLocked
  165. 2035Partition Array Into Two Arrays to Minimize Sum DifferenceWatch
  166. 2040Kth Smallest Product of Two Sorted ArraysWatch
  167. 2054Two Best Non-Overlapping EventsWatch
  168. 2055Plates Between CandlesWatch
  169. 2064Minimized Maximum of Products Distributed to Any StoreWatch
  170. 2070Most Beautiful Item for Each QueryWatch
  171. 2071Maximum Number of Tasks You Can AssignWatch
  172. 2080Range Frequency QueriesWatch
  173. 2089Find Target Indices After Sorting ArrayWatch
  174. 2106Maximum Fruits Harvested After at Most K StepsWatch
  175. 2111Minimum Operations to Make the Array K-IncreasingWatch
  176. 2137Pour Water Between Buckets to Make Water Levels EqualLocked
  177. 2141Maximum Running Time of N ComputersWatch
  178. 2179Count Good Triplets in an ArrayWatch
  179. 2187Minimum Time to Complete TripsWatch
  180. 2223Sum of Scores of Built StringsWatch
  181. 2226Maximum Candies Allocated to K ChildrenWatch
  182. 2234Maximum Total Beauty of the GardensWatch
  183. 2250Count Number of Rectangles Containing Each PointWatch
  184. 2251Number of Flowers in Full BloomWatch
  185. 2258Escape the Spreading FireWatch
  186. 2271Maximum White Tiles Covered by a CarpetWatch
  187. 2286Booking Concert Tickets in GroupsWatch
  188. 2300Successful Pairs of Spells and PotionsWatch
  189. 2302Count Subarrays With Score Less Than KWatch
  190. 2332The Latest Time to Catch a BusWatch
  191. 2333Minimum Sum of Squared DifferenceWatch
  192. 2354Number of Excellent PairsWatch
  193. 2358Maximum Number of Groups Entering a CompetitionWatch
  194. 2387Median of a Row Wise Sorted MatrixLocked
  195. 2389Longest Subsequence With Limited SumWatch
  196. 2398Maximum Number of Robots Within BudgetWatch
  197. 2411Smallest Subarrays With Maximum Bitwise ORWatch
  198. 2424Longest Uploaded PrefixWatch
  199. 2426Number of Pairs Satisfying InequalityWatch
  200. 2439Minimize Maximum of ArrayWatch
  201. 2448Minimum Cost to Make Array EqualWatch
  202. 2454Next Greater Element IVWatch
  203. 2476Closest Nodes Queries in a Binary Search TreeWatch
  204. 2498Frog Jump IIWatch
  205. 2501Longest Square Streak in an ArrayWatch
  206. 2513Minimize the Maximum of Two ArraysWatch
  207. 2517Maximum Tastiness of Candy BasketWatch
  208. 2519Count the Number of K-Big IndicesLocked
  209. 2528Maximize the Minimum Powered CityWatch
  210. 2529Maximum Count of Positive Integer and Negative IntegerWatch
  211. 2540Minimum Common ValueWatch
  212. 2554Maximum Number of Integers to Choose From a Range IWatch
  213. 2555Maximize Win From Two SegmentsWatch
  214. 2557Maximum Number of Integers to Choose From a Range IILocked
  215. 2560House Robber IVWatch
  216. 2563Count the Number of Fair PairsWatch
  217. 2565Subsequence With the Minimum ScoreWatch
  218. 2576Find the Maximum Number of Marked IndicesWatch
  219. 2589Minimum Time to Complete All TasksWatch
  220. 2594Minimum Time to Repair CarsWatch
  221. 2601Prime Subtraction OperationWatch
  222. 2602Minimum Operations to Make All Array Elements EqualWatch
  223. 2604Minimum Time to Eat All GrainsLocked
  224. 2616Minimize the Maximum Difference of PairsWatch
  225. 2659Make Array EmptyWatch
  226. 2702Minimum Operations to Make Numbers Non-positiveLocked
  227. 2713Maximum Strictly Increasing Cells in a MatrixWatch
  228. 2736Maximum Sum QueriesWatch
  229. 2779Maximum Beauty of an Array After Applying OperationWatch
  230. 2790Maximum Number of Groups With Increasing LengthWatch
  231. 2812Find the Safest Path in a GridWatch
  232. 2817Minimum Absolute Difference Between Elements With ConstraintWatch
  233. 2819Minimum Relative Loss After Buying ChocolatesLocked
  234. 2824Count Pairs Whose Sum is Less than TargetWatch
  235. 2826Sorting Three GroupsWatch
  236. 2830Maximize the Profit as the SalesmanWatch
  237. 2831Find the Longest Equal SubarrayWatch
  238. 2838Maximum Coins Heroes Can CollectLocked
  239. 2856Minimum Array Length After Pair RemovalsWatch
  240. 2861Maximum Number of AlloysWatch
  241. 2926Maximum Balanced Subsequence SumWatch
  242. 2936Number of Equal Numbers BlocksLocked
  243. 2940Find Building Where Alice and Bob Can MeetWatch
  244. 2941Maximum GCD-Sum of a SubarrayLocked
  245. 2945Find Maximum Non-decreasing Array LengthWatch
  246. 2967Minimum Cost to Make Array EqualindromicWatch
  247. 2968Apply Operations to Maximize Frequency ScoreWatch
  248. 2970Count the Number of Incremovable Subarrays IWatch
  249. 2972Count the Number of Incremovable Subarrays IIWatch
  250. 2981Find Longest Special Substring That Occurs Thrice IWatch
  251. 2982Find Longest Special Substring That Occurs Thrice IIWatch
  252. 3006Find Beautiful Indices in the Given Array IWatch
  253. 3007Maximum Number That Sum of the Prices Is Less Than or Equal to KWatch
  254. 3008Find Beautiful Indices in the Given Array IIWatch
  255. 3048Earliest Second to Mark Indices IWatch
  256. 3049Earliest Second to Mark Indices IIWatch
  257. 3109Find the Index of PermutationLocked
  258. 3113Find the Number of Subarrays Where Boundary Elements Are MaximumWatch
  259. 3116Kth Smallest Amount With Single Denomination CombinationWatch
  260. 3117Minimum Sum of Values by Dividing ArrayWatch
  261. 3134Find the Median of the Uniqueness ArrayWatch
  262. 3135Equalize Strings by Adding or Removing Characters at EndsLocked
  263. 3143Maximum Points Inside the SquareWatch
  264. 3145Find Products of Elements of Big ArrayWatch
  265. 3152Special Array IIWatch
  266. 3155Maximum Number of Upgradable ServersLocked
  267. 3161Block Placement QueriesWatch
  268. 3171Find Subarray With Bitwise OR Closest to KWatch
  269. 3186Maximum Total Damage With Spell CastingWatch
  270. 3209Number of Subarrays With AND Value of KWatch
  271. 3231Minimum Number of Increasing Subsequence to Be RemovedLocked
  272. 3261Count Substrings That Satisfy K-Constraint IIWatch
  273. 3281Maximize Score of Numbers in RangesWatch
  274. 3288Length of the Longest Increasing PathWatch
  275. 3291Minimum Number of Valid Strings to Form Target IWatch
  276. 3292Minimum Number of Valid Strings to Form Target IIWatch
  277. 3296Minimum Number of Seconds to Make Mountain Height ZeroWatch
  278. 3312Sorted GCD Pair QueriesWatch
  279. 3323Minimize Connected Groups by Inserting IntervalLocked
  280. 3344Maximum Sized ArrayLocked
  281. 3346Maximum Frequency of an Element After Performing Operations IWatch
  282. 3347Maximum Frequency of an Element After Performing Operations IIWatch
  283. 3350Adjacent Increasing Subarrays Detection IIWatch
  284. 3356Zero Array Transformation IIWatch
  285. 3357Minimize the Maximum Adjacent Element DifferenceWatch
  286. 3369Design an Array Statistics Tracker Locked
  287. 3398Smallest Substring With Identical Characters IWatch
  288. 3399Smallest Substring With Identical Characters IIWatch
  289. 3413Maximum Coins From K Consecutive BagsWatch
  290. 3414Maximum Score of Non-overlapping IntervalsWatch
  291. 3419Minimize the Maximum Edge Weight of GraphWatch
  292. 3449Maximize the Minimum Game ScoreWatch
  293. 3453Separate Squares IWatch
  294. 3454Separate Squares IIWatch
  295. 3455Shortest Matching SubstringWatch
  296. 3464Maximize the Distance Between Points on a SquareWatch
  297. 3477Fruits Into Baskets IIWatch
  298. 3479Fruits Into Baskets IIIWatch
  299. 3488Closest Equal Element QueriesWatch
  300. 3501Maximize Active Section with Trade IIWatch
  301. 3508Implement RouterWatch
  302. 3520Minimum Threshold for Inversion Pairs CountLocked
  303. 3532Path Existence Queries in a Graph IWatch
  304. 3534Path Existence Queries in a Graph IIWatch
  305. 3585Find Weighted Median Node in TreeWatch
  306. 3600Maximize Spanning Tree Stability with UpgradesWatch
  307. 3605Minimum Stability Factor of ArrayWatch
  308. 3608Minimum Time for K Connected ComponentsWatch
  309. 3613Minimize Maximum Component CostWatch
  310. 3620Network Recovery PathwaysWatch
  311. 3633Earliest Finish Time for Land and Water Rides IWatch
  312. 3634Minimum Removals to Balance ArrayWatch
  313. 3635Earliest Finish Time for Land and Water Rides IIWatch
  314. 3636Threshold Majority QueriesWatch
  315. 3639Minimum Time to Activate StringWatch
  316. 3656Determine if a Simple Graph ExistsLocked
  317. 3661Maximum Walls Destroyed by RobotsWatch
  318. 3709Design Exam Scores TrackerWatch
  319. 3710Maximum Partition FactorWatch
  320. 3722Lexicographically Smallest String After ReverseWatch
  321. 3733Minimum Time to Complete All DeliveriesWatch
  322. 3735Lexicographically Smallest String After Reverse IILocked
  323. 3748Count Stable SubarraysWatch
  324. 3759Count Elements With at Least K Greater ValuesWatch
  325. 3762Minimum Operations to Equalize SubarraysWatch
  326. 3766Minimum Operations to Make Binary PalindromeWatch
  327. 3771Total Score of Dungeon RunsWatch
  328. 3801Minimum Cost to Merge Sorted ListsWatch
  329. 3807Minimum Cost to Repair Edges to Traverse a GraphLocked
  330. 3814Maximum Capacity Within BudgetWatch
  331. 3824Minimum K to Reduce Array Within LimitWatch
  332. 3825Longest Strictly Increasing Subsequence With Non-Zero Bitwise ANDWatch
  333. 3826Minimum Partition ScoreWatch
  334. 3896Minimum Operations to Transform Array into Alternating PrimeWatch
  335. 3911K-th Smallest Remaining Even Integer in Subarray QueriesWatch
  336. 3920Maximize Fixed Points After DeletionsWatch
  337. 3924Minimum Threshold Path With Limited Heavy EdgesWatch
  338. 3929Minimum Partition Score IILocked
  339. 3932Count K-th Roots in a RangeWatch
  340. 3934Smallest Unique SubarrayWatch
  341. 3956Maximum Sum of M Non-Overlapping Subarrays IWatch
  342. 3957Maximum Sum of M Non-Overlapping Subarrays IIWatch
  343. 3971Maximum Total ValueWatch
  344. 3985Palindromic Subarray SumWatch
  345. 4008Minimum Initial Strength to Defeat All MonstersWatch
  346. 4012Count of Unfinished Tasks After Each ShiftWatch
  347. 4016Maximum Area of Two Non-Overlapping Square SubmatricesWatch
  348. 4022K-th Digit in Infinite StringWatch
  349. 4031Find All Numbers Disappeared in an Array IIWatch
  350. 4051Count Subarrays with Distant SumsWatch
  351. 4053Minimum Operations to Make Every Element PalindromicWatch
  352. 4055Count Shadow Pairs IIWatch