Skip to content

Completed Two-Pointers-2#1792

Open
ManasviReddy25 wants to merge 1 commit into
super30admin:masterfrom
ManasviReddy25:master
Open

Completed Two-Pointers-2#1792
ManasviReddy25 wants to merge 1 commit into
super30admin:masterfrom
ManasviReddy25:master

Conversation

@ManasviReddy25

Copy link
Copy Markdown

No description provided.

@super30admin

Copy link
Copy Markdown
Owner

Merging of 2 arrays (Problem1.py)

  1. Wrong Problem: You submitted a solution for "Remove Duplicates from Sorted Array II" instead of "Merge Sorted Array". Please ensure you're solving the correct problem assigned.

  2. Code Issues: Even for the problem you attempted, there are bugs:

    • Using fast in condition check before incrementing causes redundant comparisons
    • The loop variable i is unused while fast is manually managed, which is confusing
  3. Missing Solution: You haven't provided any solution for the actual merge problem. The correct approach would use three pointers starting from the end of the arrays.

  4. Readability: While the comments are present, the variable naming could be clearer (e.g., count is actually tracking consecutive occurrences).

VERDICT: NEEDS_IMPROVEMENT


Search 2D sorted matrix II (Problem2.py)

Strengths:

  • The code for the merge problem is well-structured and follows good practices
  • Clear variable naming (p1, p2, p3) with comments explaining their purposes
  • Correct in-place merging logic using three pointers
  • Handles edge cases properly (copying remaining nums2 elements)

Areas for Improvement:

  • This submission is for the wrong problem entirely
  • The student should ensure they are solving the problem that was actually assigned
  • For the merge problem specifically, the solution is already optimal

The submitted code solves a completely different problem than what was requested. To solve "Search 2D sorted matrix II," the student would need to implement a search algorithm that leverages the sorted row and column properties, such as starting from the top-right corner and moving left/down based on comparisons, or performing binary search on each row.

VERDICT: NEEDS_IMPROVEMENT


Edit and Remove Duplicates in an array (Problem3.py)

  1. Wrong Problem: You have submitted a solution for "Search a 2D Matrix II" instead of "Edit and Remove Duplicates in an array" (which appears to be a variant of LeetCode Completed Two Pointers2 - Please review #80 - Remove Duplicates from Sorted Array II). These are completely different problems.

  2. Missing Implementation: There is no code to remove duplicates or limit elements to at most 2 occurrences. The student's solution searches for a target value in a 2D matrix.

  3. What you should do: You need to implement a two-pointer solution where:

    • A slow pointer tracks where to place the next valid element
    • A fast pointer scans through the array
    • Count consecutive occurrences and only copy elements when count ≤ 2
    • Return the count of valid elements (slow pointer position)
  4. Reference approach hint: The correct solution uses a while loop with fast pointer, maintains a count of consecutive duplicates, and only copies elements to slow position when count is ≤ 2.

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.

3 participants