Skip to content

Completed Binary Search 1#2503

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

Completed Binary Search 1#2503
RitikaC1 wants to merge 1 commit into
super30admin:masterfrom
RitikaC1:master

Conversation

@RitikaC1

@RitikaC1 RitikaC1 commented Jun 6, 2026

Copy link
Copy Markdown

No description provided.

@super30admin

Copy link
Copy Markdown
Owner

Search inside a Rotated Sorted Array (problem-1.py)

  1. Major Issue - Wrong Problem: You solved "Search a 2D Matrix" instead of "Search in Rotated Sorted Array". Please read the problem description carefully before implementing.

  2. For the Rotated Array Problem: The solution should use binary search with logic to determine which half is sorted, then decide which side to search based on whether the target lies within the sorted half's range.

  3. For Your 2D Matrix Solution: Your implementation is actually well-structured for that problem. The binary search logic is correct, and the row/column calculations are appropriate. However, note that your while condition should be low <= high instead of low < high to handle edge cases correctly.

  4. Time Complexity: For the rotated array problem, O(log n) is achievable with proper binary search. Your matrix solution has O(log(n*m)) which is also logarithmic.

  5. Space Complexity: O(1) is correct for both approaches.

  6. Code Quality: Your code is readable with clear variable names. Consider adding comments to explain the logic.

VERDICT: NEEDS_IMPROVEMENT


Search Inside a Sorted Array whose Length is unknown (problem-2.py)

The implementation for a rotated sorted array is solid - the logic correctly handles both sorted halves and the binary search conditions are properly implemented. However, this solution is for a different problem. For the "Search in Sorted Array of Unknown Length" problem, you need to:

  1. Use the ArrayReader interface (reader.get(index)) instead of direct array access
  2. Implement exponential search first to find the upper bound (doubling high until reader.get(high) >= target or out of bounds)
  3. Then perform binary search between low and high
  4. Handle the special sentinel value (2^31 - 1) that indicates out-of-bounds access

The time complexity is O(log n) which meets the requirement, and space complexity is O(1) which is optimal. The code quality is good with clear comments and readable structure.

FEEDBACK:
Your rotated sorted array solution is well-implemented with correct binary search logic for both cases. However, you've solved a different problem. For the unknown-length sorted array problem, you need to use the ArrayReader interface, implement exponential search to find bounds, and then binary search. The sentinel value handling (2^31 - 1) is also crucial.

VERDICT: NEEDS_IMPROVEMENT


Search a 2D Matrix (problem-3.py)

  • The student appears to have submitted code for a different LeetCode problem (LeetCode 702 - Search in Sorted Array) rather than the problem at hand (LeetCode 74 - Search a 2D Matrix)
  • The approach for infinite sorted array (exponential search + binary search) is a valid technique for that problem, but it's not needed for the 2D matrix problem where we can directly treat the 2D array as 1D
  • The reference solution shows the correct approach: treat the 2D matrix as a flattened 1D array and apply binary search directly
  • Need to fix the syntax error (minmid) and ensure proper variable scoping
  • For the 2D matrix problem, the simpler approach is to calculate row and column indices directly from the mid index

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