Skip to content

Completed Binary-Search-1 - #2525

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

ManasviReddy25 wants to merge 1 commit into
super30admin:masterfrom
ManasviReddy25:master

Conversation

@ManasviReddy25

Copy link
Copy Markdown

No description provided.

@super30admin

Copy link
Copy Markdown
Owner

Search in Rotated Sorted Array (Problem1.py)

You have solved "Search a 2D Matrix" (LeetCode 74) instead of the assigned problem "Search in Rotated Sorted Array" (LeetCode 33). These are two distinct problems with different approaches:

  • Search a 2D Matrix: The matrix is fully sorted (each row sorted, and the first element of each row is greater than the last element of the previous row). Your approach of treating it as a flattened 1D array is correct for this problem.

  • Search in Rotated Sorted Array: The 1D array is sorted but then rotated at some pivot. For example, [0,1,2,4,5,6,7] rotated at index 3 becomes [4,5,6,7,0,1,2]. The key insight is that at any point, one half of the array is still sorted. You need to determine which half is sorted, then check if the target lies within that sorted half. If yes, search there; if no, search the other half.

Please re-read the problem statement carefully and resubmit a solution that:

  1. Handles a rotated sorted 1D array
  2. Uses the property that one half is always sorted
  3. Achieves O(log n) time complexity

VERDICT: NEEDS_IMPROVEMENT


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

Return ONLY the comments in the Python code block as specified. ```python

Evaluation of the Student's Solution

1. Correctness:

The student's solution is for a DIFFERENT problem - "Search in a Rotated Sorted Array"

(LeetCode 33), not "Search in a Sorted Array of Unknown Size" (LeetCode 702).

The student's solution does not use ArrayReader interface, does not handle out-of-bounds

returns, and does not implement the exponential search to find bounds.

This solution does NOT solve the assigned problem.

2. Time Complexity:

O(log n) - matches the required complexity, but for the wrong problem.

3. Search Strategy:

The reference solution uses exponential search to find bounds, then binary search.

The student's solution uses a modified binary search for rotated arrays.

4. Code Quality:

The code is well-structured and readable for the problem it solves, but it's solving

the wrong problem entirely.


FEEDul

VERDICT: NEEDS_IMPROVEMENT

---

### Search a 2D Matrix (Problem3.py)
It appears you have submitted a solution to a different problem ("Search in Infinite Sorted Array" / LeetCode 702) instead of the assigned problem ("Search a 2D Matrix" / LeetCode 74). 

To correctly solve "Search a 2D Matrix":
1. **Understand the key insight**: Because each row's first element is greater than the previous row's last element, the entire matrix can be treated as a single sorted 1D array of length `m * n`.
2. **Map 1D index to 2D coordinates**: Given an index `mid`, the row is `mid / n` and the column is `mid % n`.
3. **Apply binary search**: Use standard binary search on the range `[0, m*n - 1]`, accessing `matrix[mid/n][mid%n]` at each step.
4. **Achieve O(log(m*n)) time complexity** as required.

Please re-submit a solution that actually addresses the "Search a 2D Matrix" problem. Make sure to:
- Take `int[][] matrix` and `int target` as inputs
- Return `true` if target exists in the matrix, `false` otherwise
- Use binary search with the 1D-to-2D index mapping technique

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.

3 participants