Submit Two-Pointers-2 PR - #1799
Conversation
Implement merge function to combine two sorted arrays in-place.
Implement a solution to remove duplicates from a sorted array, allowing at most two occurrences of each element.
Implement searchMatrix method to find target in 2D matrix.
Merge Sorted Array (Problem_1.py)It appears there has been a significant mix-up. You have submitted a solution for "Remove Duplicates from Sorted Array II" instead of "Merge Sorted Array". To solve "Merge Sorted Array" correctly, you should:
Here's a skeleton to get you started: class Solution:
def merge(self, nums1, m, nums2, n):
p1, p2 = m - 1, n - 1
idx = m + n - 1
while p1 >= 0 and p2 >= 0:
if nums2[p2] > nums1[p1]:
nums1[idx] = nums2[p2]
p2 -= 1
else:
nums1[idx] = nums1[p1]
p1 -= 1
idx -= 1
while p2 >= 0:
nums1[idx] = nums2[p2]
p2 -= 1
idx -= 1Please re-submit with the correct solution for "Merge Sorted Array". VERDICT: NEEDS_IMPROVEMENT Search a 2D Matrix II (Problem_2.py)VERDICT REASON: [Brief reason for verdict] VERDICT appears to be NEEDS_IMPROVEMENT VERDICT: NEEDS_IMPROVEMENT Remove Duplicates from Sorted Array II (Problem_3.py)It appears that you have submitted a solution to the wrong problem. The problem you need to solve is "Remove Duplicates from Sorted Array II," which involves modifying a sorted array in-place so that each unique element appears at most twice. Your submitted code solves "Search a 2D Matrix II" instead. To correctly solve the assigned problem, you should:
For example, a correct approach would look like: class Solution:
def removeDuplicates(self, nums: List[int]) -> int:
slow = 0
count = 0
for fast in range(len(nums)):
if fast == 0 or nums[fast] != nums[fast - 1]:
count = 1
else:
count += 1
if count <= 2:
nums[slow] = nums[fast]
slow += 1
return slowPlease re-submit with the correct solution to the assigned problem. VERDICT: NEEDS_IMPROVEMENT |
No description provided.