Skip to main content

Command Palette

Search for a command to run...

Day 18: Tackling Medium-Level Binary Search

Published
2 min readView as Markdown
Day 18: Tackling Medium-Level Binary Search

Today was both exciting and challenging as I delved into the world of medium-level Binary Search problems on LeetCode.

  1. Problem 1: Search in Rotated Sorted Array (LeetCode #33) This problem presented a unique twist to the traditional Binary Search. I had to search for a target element in a rotated sorted array. The key was to adapt the Binary Search approach to handle the rotated nature of the array. Careful consideration of the pivot point and adjusting the search range accordingly led me to a satisfying solution.

  2. Problem 2: Search in a 2D Matrix (LeetCode #74) The second challenge took Binary Search to a two-dimensional space. I was given a matrix where each row was sorted, and the first element of each row was greater than the last element of the previous row. The task was to find if a given target existed in the matrix. Breaking down the matrix into rows and performing Binary Search on each row made for an elegant solution.

  3. Problem 3: Find Kth Smallest Element in a Sorted Matrix (LeetCode #378) The final problem of the day tested my ability to find the Kth smallest element in a sorted matrix. Binary Search was my go-to approach here as well. I iteratively narrowed down the search range and counted the number of elements smaller than the mid-point. This approach efficiently led me to the desired Kth smallest element.

Day 18 was a remarkable journey into the realm of medium-level Binary Search challenges on LeetCode. These problems pushed me to think creatively and adapt the Binary Search approach to diverse scenarios.

More from this blog

Zaid Parkar : DSA (C++)

37 posts