Skip to content

two pointers-2#1793

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

two pointers-2#1793
sudheerkreddy wants to merge 1 commit into
super30admin:masterfrom
sudheerkreddy:master

Conversation

@sudheerkreddy

@sudheerkreddy sudheerkreddy commented Jun 21, 2026

Copy link
Copy Markdown

@super30admin

Copy link
Copy Markdown
Owner

Merging of 2 arrays (MergeSortedArray.java)

Strengths:

  • Excellent implementation that matches the optimal approach
  • Clean and readable code with appropriate comments
  • Correctly handles edge cases (empty arrays)
  • Proper use of three-pointer technique from the end

Areas for minor improvement:

  • Could add a brief comment explaining why we don't need to copy remaining elements from nums1 (they're already in place)
  • The while loop condition p1 >= 0 && p2 >= 0 is correct, but for clarity, you could note that when only p2 remains, we must copy from nums2 (since nums1's remaining elements are already in their final positions)

The solution is solid and production-ready. Well done!

VERDICT: PASS


Search 2D sorted matrix II (RemoveDuplicatesFromSortedArray2.java)

  1. Wrong Problem: The submitted code solves a completely different problem. The "Search 2D Matrix II" problem requires searching for a target in a 2D matrix where rows and columns are sorted, not removing duplicates from a sorted array.

  2. No Comparison Possible: Since the solution doesn't address the given problem, we cannot meaningfully compare it to the reference solution in terms of time/space complexity for this specific task.

  3. Code Quality (for wrong problem): The code for "Remove Duplicates II" is actually well-written - it uses the two-pointer technique correctly, handles the count tracking properly, and is readable. However, this doesn't help with the assigned problem.

  4. What the student should have done: For the Search 2D Matrix II problem, a common efficient approach is:

    • Start from top-right corner (or bottom-left)
    • If current element equals target, return true
    • If current element > target, move left
    • If current element < target, move down
    • This gives O(m+n) time complexity

VERDICT: NEEDS_IMPROVEMENT


Edit and Remove Duplicates in an array (Search2DMatrix2.java)

  • The submitted code solves a different problem (Search 2D Matrix II) and does not address the Edit and Remove Duplicates problem at all
  • No attempt was made to implement the duplicate removal logic with the constraint of allowing at most 2 occurrences per element
  • No in-place modification logic is present
  • Please ensure you submit the correct solution for the problem you are attempting to solve

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