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.
Description
We need to efficiently search for a target value in a matrix where rows and columns are sorted in ascending order. The matrix is structured such that lower values are towards the top-left corner and higher values are towards the bottom-right corner.
Approach
The provided solution utilizes a two-pointer approach starting from the bottom-left corner of the matrix:
Begin from the bottom-left corner (matrix[n-1][0]).
If the current value is equal to the target, return true.
If the current value is greater than the target, move upwards to the next row (row--).
If the current value is less than the target, move to the right to the next column (col++).
This approach efficiently narrows down the search space by leveraging the sorted properties of both rows and columns.
Put check marks:
How Has This Been Tested?
Test Case 1:
Test Case 2:
Make sure all below guidelines are followed else PR will get Reject: