Skip to content

Complete Two-Pointer-2 - #1800

Open
satish-paraddi wants to merge 3 commits into
super30admin:masterfrom
satish-paraddi:master
Open

satish-paraddi wants to merge 3 commits into
super30admin:masterfrom
satish-paraddi:master

Conversation

@satish-paraddi

Copy link
Copy Markdown

No description provided.

@super30admin

Copy link
Copy Markdown
Owner

Merge Sorted Array (Problem1.py)

It appears that you've submitted code for a different problem (Remove Duplicates II) instead of the Merge Sorted Array problem. Please:

  1. Re-read the problem carefully: The task is to merge nums1 and nums2 into nums1 in sorted order, modifying nums1 in-place.
  2. Use the correct method signature: def merge(self, nums1: List[int], m: int, nums2: List[int], n: int) -> None:
  3. Implement the merge logic: A common efficient approach is to use three pointers starting from the end of nums1 (index m+n-1), comparing elements from the end of both arrays and placing the larger one at the current position. This achieves O(m+n) time and O(1) space.
  4. Handle edge cases: Consider cases where n=0 (nothing to merge) or m=0 (all elements come from nums2).

Please resubmit with the correct solution for the Merge Sorted Array problem.

VERDICT: NEEDS_IMPROVEMENT


Search a 2D Matrix II (Problem2.py)

It appears that you have submitted a solution for a different problem (Merge Sorted Array) instead of the problem that was asked (Search a 2D Matrix II). The two problems are completely unrelated:

  1. Search a 2D Matrix II: Requires searching for a target value in a 2D matrix where each row is sorted left-to-right and each column is sorted top-to-bottom.

  2. Merge Sorted Array: Requires merging two sorted arrays into one sorted array in-place.

Please re-read the problem statement and submit a solution that actually addresses the 2D matrix search problem. For this problem, you could consider:

  • The O(m log n) approach using binary search on each row
  • The O(m + n) approach starting from the top-right corner and eliminating one row or column at each step

VERDICT: NEEDS_IMPROVEMENT


Remove Duplicates from Sorted Array II (Problem3.py)

It appears that you have submitted code for the wrong problem. The problem you need to solve is "Remove Duplicates from Sorted Array II," which involves:

  1. Taking a sorted integer array as input
  2. Modifying it in-place so that each unique element appears at most twice
  3. Returning the count k of valid elements
  4. The first k elements of the array should contain the final result

Your submitted code solves "Search a 2D Matrix II" instead. Please:

  1. Re-read the problem statement carefully
  2. Implement the correct algorithm using a two-pointer approach (slow and fast pointers)
  3. Track the count of consecutive duplicates and only keep elements when count ≤ 2
  4. Test your solution against the provided examples

A correct approach would use a slow pointer for the position to write valid elements and a fast pointer to iterate through the array, with a counter to track occurrences of the current element.

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