Skip to content

Binary-Search-1 problems - #2523

Open
paragc05 wants to merge 1 commit into
super30admin:masterfrom
paragc05:master
Open

Binary-Search-1 problems#2523
paragc05 wants to merge 1 commit into
super30admin:masterfrom
paragc05:master

Conversation

@paragc05

@paragc05 paragc05 commented Aug 1, 2026

Copy link
Copy Markdown

No description provided.

@super30admin

Copy link
Copy Markdown
Owner

Search in Rotated Sorted Array (LC33_BS_rotated_sorted_array.py)

Excellent work! Your solution is correct, efficient, and well-documented. A few minor suggestions for future improvement:

  1. Edge case consideration: While your solution handles all cases correctly, you could add a brief comment about edge cases (e.g., when the array isn't rotated, or when the array has only one element) to demonstrate deeper understanding.

  2. Alternative approach: For learning purposes, you might also explore finding the pivot point first (using binary search to find the minimum element), then performing a standard binary search on the appropriate half. This is another common approach to this problem.

  3. Testing: Consider adding test cases in your submission to verify correctness across various scenarios (rotated array, non-rotated array, target at boundaries, target not present).

Overall, this is a clean, professional solution that demonstrates strong understanding of binary search in rotated arrays.

VERDICT: PASS


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

Excellent work! Your solution is a clean, correct implementation of the exponential search + binary search approach. The code is well-commented and follows Python best practices. The approach is optimal for this problem with O(log n) time complexity.

VERDICT: PASS


Search a 2D Matrix (LC74_BS_2DMatrix.py)

Strengths:

  • Correct implementation of the binary search approach
  • Optimal time and space complexity
  • Good comments explaining the approach
  • Clean and readable code

Areas for improvement:

  • Variable naming: Consider using rows and cols instead of m and n, or follow the convention where m represents rows and n represents columns. The current naming (m = len(matrix[0]) for columns and n = len(matrix) for rows) is unconventional and could be confusing.
  • The comment "once we know what row the target exist we perform binary search" is slightly misleading. The solution performs a single binary search on the flattened array, not two separate binary searches. Consider revising this comment for clarity.
  • Adding a brief explanation of why the division and modulo operations work (i.e., mid // m gives the row and mid % m gives the column) would be helpful for readers.

VERDICT: PASS

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