Skip to content

Two pointers 2#1786

Open
YogeshPardeshi wants to merge 3 commits into
super30admin:masterfrom
YogeshPardeshi:master
Open

Two pointers 2#1786
YogeshPardeshi wants to merge 3 commits into
super30admin:masterfrom
YogeshPardeshi:master

Conversation

@YogeshPardeshi
Copy link
Copy Markdown

No description provided.

@super30admin
Copy link
Copy Markdown
Owner

Merging of 2 arrays (Problem1.java)

  1. Wrong Problem: The submitted solution solves "Remove Duplicates II" (keeping at most 2 duplicates), not the "Merge Sorted Array" problem. Please ensure you read and solve the correct problem.

  2. Missing Solution: There is no attempt to merge two sorted arrays. The correct approach would be:

    • Use three pointers: one for nums1 (at position m-1), one for nums2 (at position n-1), and one for the merge position (at position m+n-1)
    • Compare elements from both arrays from the end
    • Place the larger element at the merge position
    • Copy any remaining elements from nums2 if needed
  3. Code Quality: The submitted code itself is well-structured for its intended problem (remove duplicates), with clear variable naming and logical flow. However, it doesn't address the assigned problem.

VERDICT: NEEDS_IMPROVEMENT


Search 2D sorted matrix II (Problem2.java)

Strengths:

  • The code for merging sorted arrays is syntactically correct and follows proper Java conventions
  • Variable naming is clear (p1, p2, idx)
  • The two-pointer approach from the end is an efficient way to solve the merge problem

Critical Issues:

  1. Wrong Problem: The solution solves "Merge Sorted Array" instead of "Search 2D Matrix II"
  2. Missing Solution: There is no implementation for the actual problem - no matrix search logic exists
  3. Method Signature Mismatch: The problem requires searchMatrix(vector<vector<int>>& matrix, int target) but the student submitted merge(int[] nums1, int m, int[] nums2, int n)

What the student should do:

  • Implement binary search on each row (as shown in reference) OR
  • Use the optimal approach starting from top-right corner (O(m+n))
  • The correct method should search for a target value in a 2D sorted matrix

VERDICT: NEEDS_IMPROVEMENT


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

The student appears to have submitted code for the wrong problem. The solution provided solves the matrix search problem, not the duplicate removal problem described in the prompt.

Strengths of the submitted code:

  • Clean implementation of the bottom-left corner search technique
  • Proper variable naming and structure
  • Correct handling of boundary conditions

Areas for improvement:

  • The submitted solution addresses a completely different problem
  • For the actual problem (removing duplicates with max 2 occurrences), the student should implement a two-pointer approach similar to the reference solution
  • Need to handle the count of occurrences and only keep elements that appear at most twice

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