Skip to content

Completed Leetcode 240, 80 and 88 - #1798

Open
allurkarsneha wants to merge 1 commit into
super30admin:masterfrom
allurkarsneha:leetcode240-80-88
Open

Completed Leetcode 240, 80 and 88#1798
allurkarsneha wants to merge 1 commit into
super30admin:masterfrom
allurkarsneha:leetcode240-80-88

Conversation

@allurkarsneha

Copy link
Copy Markdown

No description provided.

@super30admin

Copy link
Copy Markdown
Owner

Merge Sorted Array (Problem 1- Leetcode80.py)

It appears that you've submitted a solution for a different problem (Remove Duplicates from Sorted Array II) instead of the Merge Sorted Array problem. To correctly solve the Merge Sorted Array problem, you need to:

  1. Merge two sorted arrays (nums1 and nums2) into nums1 in non-decreasing order.
  2. The first m elements of nums1 are the actual values, and the last n elements are placeholders (0s).
  3. The result should be stored in nums1 itself, not returned as a new array.
  4. Aim for O(m + n) time complexity and O(1) extra space.

A common approach is to use three pointers starting from the end of the arrays:

  • One pointer at the end of the actual elements in nums1 (index m-1)
  • One pointer at the end of nums2 (index n-1)
  • One pointer at the end of nums1 (index m+n-1)

Compare elements from the end and place the larger one at the end of nums1, moving backwards. This way, you don't need extra space and can achieve O(m + n) time complexity.

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

VERDICT: NEEDS_IMPROVEMENT


Search a 2D Matrix II (Problem 2- Leetcode88.py)

It appears that you have submitted a solution for a different problem (LeetCode 88 - Merge Sorted Array) instead of the requested problem (LeetCode 240 - Search a 2D Matrix II).

For the "Search a 2D Matrix II" problem, you need to:

  1. Take a 2D matrix and a target value as input
  2. Search for the target in the matrix efficiently, leveraging the properties that:
    • Each row is sorted in ascending order
    • Each column is sorted in ascending order

A common approach is to start from the top-right corner (or bottom-left corner) and use the sorted properties to eliminate either a row or column at each step, achieving O(m+n) time complexity. Alternatively, you could perform binary search on each row, achieving O(m log n) time complexity as shown in the reference solution.

Please re-submit your solution for the correct problem.

VERDICT: NEEDS_IMPROVEMENT


Remove Duplicates from Sorted Array II (Problem 3- Leetcode240.py)

It appears that you've submitted a solution for a different problem. The assigned problem was "Remove Duplicates from Sorted Array II" (LeetCode 80), but your solution is for "Search a 2D Matrix II" (LeetCode 240).

To solve the actual problem, you need to:

  1. Modify the input array in-place to allow each unique element to appear at most twice
  2. Maintain the relative order of elements
  3. Return the count of elements kept (k)
  4. Use O(1) extra space

A common approach is to use a two-pointer technique:

  • Use a slow pointer to track the position where valid elements should be placed
  • Use a fast pointer to iterate through the array
  • Keep a count of how many times the current element has appeared
  • Only copy the element to the slow pointer position if its count is ≤ 2

Please resubmit with the correct solution for "Remove Duplicates from Sorted Array II".

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