Skip to content

Submit Binary-Search-1 PR - #2519

Open
agk-s30 wants to merge 3 commits into
super30admin:masterfrom
agk-s30:master
Open

Submit Binary-Search-1 PR#2519
agk-s30 wants to merge 3 commits into
super30admin:masterfrom
agk-s30:master

Conversation

@agk-s30

@agk-s30 agk-s30 commented Aug 1, 2026

Copy link
Copy Markdown

No description provided.

agk-s30 added 3 commits July 31, 2026 17:51
Implement binary search in a sorted array of unknown size.
Implement binary search for rotated sorted array.
Implement binary search to find target in 2D matrix.
@super30admin

Copy link
Copy Markdown
Owner

Search in Rotated Sorted Array (Exercise_1.py)

You have submitted a solution for "Search a 2D Matrix" (LeetCode 74) instead of "Search in Rotated Sorted Array" (LeetCode 33). These are two different problems:

  • Search in Rotated Sorted Array: Given a 1D array that was originally sorted but rotated at some pivot, find the target value. The key challenge is determining which half of the array is properly sorted to decide which direction to search.

  • Search a 2D Matrix: Given a 2D matrix where each row is sorted and the first element of each row is greater than the last element of the previous row, find the target value. This can be solved by treating the matrix as a 1D array.

To solve the actual problem, you need to:

  1. Use binary search on the rotated array
  2. At each step, determine which half (left or right) is properly sorted
  3. Check if the target falls within the sorted half; if yes, search there; if no, search the other half

Here's a hint for the correct approach:

  • Compare nums[low] with nums[mid] to determine if the left half is sorted
  • If left half is sorted and target is within [nums[low], nums[mid]), search left; otherwise search right
  • If right half is sorted and target is within (nums[mid], nums[high]], search right; otherwise search left

Please resubmit with the correct solution for "Search in Rotated Sorted Array".

VERDICT: NEEDS_IMPROVEMENT


Search in a Sorted Array of Unknown Size (Exercise_2.py)

EEVOLUTION: [PASS or NEEDS_IMPROulMENT]
EVOLUTION: [PASS or NEEDS_IMPROVEMENT]

VERDICT: NEEDS_IMPROVEMENT


Search a 2D Matrix (Exercise_3.py)

It looks like you've submitted a solution for a different problem ("Search in a Sorted Array of Unknown Size") instead of the required problem ("Search a 2D Matrix").

For the actual problem, you need to:

  1. Treat the 2D matrix as a virtual 1D sorted array of length m*n
  2. Perform binary search on this virtual array
  3. Convert the mid index back to 2D coordinates using row = mid / n and col = mid % n
  4. Compare matrix[row][col] with the target and adjust search bounds accordingly

Here's a sketch of what the solution should look like:

class Solution:
    def searchMatrix(self, matrix: List[List[int]], target: int) -> bool:
        m, n = len(matrix), len(matrix[0])
        low, high = 0, m * n - 1
        
        while low <= high:
            mid = low + (high - low) // 2
            r, c = mid // n, mid % n
            val = matrix[r][c]
            
            if val == target:
                return True
            elif val > target:
                high = mid - 1
            else:
                low = mid + 1
        
        return False

Please resubmit with the correct solution for "Search a 2D Matrix."

VERDICT: NEEDS_IMPROVEMENT

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants