Skip to content

Completed BS-1#2495

Open
prattiiksha wants to merge 1 commit into
super30admin:masterfrom
prattiiksha:bs1
Open

Completed BS-1#2495
prattiiksha wants to merge 1 commit into
super30admin:masterfrom
prattiiksha:bs1

Conversation

@prattiiksha
Copy link
Copy Markdown

  1. Search in a 2D matrix
  2. Rotated sorted array

@super30admin
Copy link
Copy Markdown
Owner

Search inside a Rotated Sorted Array (problem1.cpp)

Strengths:

  • The binary search implementation is correct and well-written
  • Good use of low + (high - low) / 2 to prevent integer overflow
  • Clean variable naming and logical structure
  • Proper handling of boundary conditions

Areas for Improvement:

  • Critical Issue: You solved the wrong problem. The assigned problem requires searching in a rotated sorted array (a 1D array with a pivot point), not a 2D matrix.
  • For the rotated sorted array problem, you need to implement a modified binary search that determines which half is sorted and decide which half to search based on where the target lies.
  • Pay close attention to problem requirements - the function should be named search (not searchMatrix) and should take a 1D vector nums as input.

VERDICT: NEEDS_IMPROVEMENT


Search Inside a Sorted Array whose Length is unknown (problem2.cpp)

Strengths:

  • Good implementation of binary search logic with proper mid-point calculation
  • Clean variable naming and consistent indentation
  • Proper handling of edge cases (returning -1 when not found)

Areas for Improvement:

  1. Wrong problem solved: This solution addresses "Search in Rotated Sorted Array" but the actual problem is "Search in a Sorted Array of Unknown Length" which requires exponential search to find bounds first.
  2. Incorrect function signature: Should accept ArrayReader& reader as parameter, not vector<int>& nums.
  3. Missing ArrayReader interface: The solution doesn't use the reader.get(i) method to access elements, which is essential for this problem.
  4. No sentinel handling: The problem states that reader.get(i) returns 2^31-1 for out-of-bounds indices - this sentinel value should be used to detect array boundaries.
  5. Algorithm approach: Needs a two-phase approach: (1) exponentially expand bounds to find target's range, (2) binary search within that range.

Recommended fix: Implement exponential search first to find the high bound, then apply binary search within that range.

VERDICT: NEEDS_IMPROVEMENT


Search a 2D Matrix

Strengths:

  1. Both solutions demonstrate a solid understanding of binary search algorithms
  2. Excellent use of low + (high - low) / 2 pattern to prevent integer overflow
  3. Clean, readable code with appropriate variable names
  4. Consistent formatting and proper use of braces
  5. Both solutions achieve optimal time and space complexity

Areas for Improvement:

  1. Problem 1: Could add a check for empty matrix edge case for robustness
  2. Problem 2: The condition nums[low] <= nums[mid] could be simplified to nums[low] < nums[mid] for cleaner logic when there are no duplicates (though the current version is correct)
  3. Consider adding brief comments explaining the algorithm logic, especially for the rotated array problem where the logic is more complex

Both solutions are well-written and solve the problems correctly with optimal complexity.

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