completed binary search - 1#2507
Open
yashhh-23 wants to merge 1 commit into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds Java implementations of common binary-search variants (rotated sorted array search, “infinite” sorted array search via reader, and 2D matrix search).
Changes:
- Added rotated sorted array binary search solution.
- Added exponential-range + binary search solution using an
ArrayReader. - Added 2D matrix binary search by flattening indices.
Reviewed changes
Copilot reviewed 3 out of 5 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| RotatedSortedArray.java | Introduces rotated-array binary search implementation and a local main driver. |
| InfinitSortedArray.java | Introduces “infinite array” search using ArrayReader, plus a local main and reader implementation. |
| 2DMatrixSearch.java | Introduces matrix binary search treating the matrix as a 1D sorted array. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| // Your code here along with comments explaining your approach in three sentences only | ||
| // Perform binary search on a rotated sorted array.Check if the left or right half is sorted and narrow search accordingly. Repeat until the target is found or search space is exhausted. | ||
| public class Solution { |
| //Double the high index until the target is within range. then Perform binary search between low and high. | ||
|
|
||
|
|
||
| public class Solution { |
Comment on lines
+11
to
+13
| public boolean searchMatrix(int[][] matrix, int target) { | ||
| int m = matrix.length; | ||
| int n = matrix[0].length; |
Comment on lines
+14
to
+27
| while (reader.get(high) < target) { | ||
| low = high; | ||
| high = high * 2; | ||
| } | ||
|
|
||
| while (low <= high) { | ||
| int mid = low + (high - low) / 2; | ||
| if (reader.get(mid) == target) return mid; | ||
| if (reader.get(mid) > target) { | ||
| high = mid - 1; | ||
| } else { | ||
| low = mid + 1; | ||
| } | ||
| } |
|
|
||
| while (reader.get(high) < target) { | ||
| low = high; | ||
| high = high * 2; |
|
|
||
|
|
||
| // Your code here along with comments explaining your approach in three sentences only | ||
| //treat 2d matrix as 1d array and apply binary search to get row and column index from mid value and compare with target tp get the result. |
Owner
Search inside a Rotated Sorted Array (RotatedSortedArray.java)Strengths:
Areas for Improvement:
The solution is functionally correct and efficient. It matches the reference solution in both approach and complexity. VERDICT: PASS Search Inside a Sorted Array whose Length is unknown (InfinitSortedArray.java)Strengths:
Areas for Improvement:
VERDICT: PASS Search a 2D Matrix (2DMatrixSearch.java)Strengths:
Areas for Improvement:
VERDICT: PASS |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.