Skip to content

Completed S30 Hashing-2#2192

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

Completed S30 Hashing-2#2192
prenastro wants to merge 1 commit into
super30admin:masterfrom
prenastro:master

Conversation

@prenastro

Copy link
Copy Markdown

No description provided.

@super30admin

Copy link
Copy Markdown
Owner

Subarray Sum Equals K (contiarray.py)

  1. Problem Understanding: Make sure you read and understand the exact problem requirements. The problem asks for counting subarrays with sum exactly equal to k, not finding maximum length of balanced subarrays.

  2. Algorithm Mismatch: The prefix sum + hashmap approach is correct for both problems, but the logic differs:

    • For "Subarray Sum Equals K": count occurrences where (currentSum - k) exists in hashmap
    • For "Contiguous Array": find longest distance between same prefix sums
  3. Code Quality: The implementation for the wrong problem is actually well-structured with good variable names and clear logic flow.

  4. Next Steps:

    • Re-read the problem statement carefully
    • For this problem, you need to count subarrays, not find maximum length
    • Use: result += map.getOrDefault(rSum - k, 0) to count matching subarrays

VERDICT: NEEDS_IMPROVEMENT


Contiguous Array (longestpalin.py)

EVALUATION

1. Correctness

The student's solution is incorrect for the given problem. The student has submitted a solution for "Longest Palindrome" (a completely different problem) instead of "Contiguous Array" (the actual problem).

The Contiguous Array problem requires finding the maximum length of a contiguous subarray with equal number of 0s and 1s, but the student's code solves a palindrome counting problem (counting pairs of characters that can form a palindrome).

2. Time Complexity

The student's solution has O(n) time complexity, which is optimal for their problem. However, since it's solving the wrong problem, this metric is not applicable here.

3. Space Complexity

The student's solution uses O(k) space where k is the number of unique characters (bounded by 26 for lowercase letters or 128 for ASCII). This is acceptable for their problem.

4. Code Quality

The code is well-structured and readable:

  • Clear variable naming
  • Good use of comments
  • Clean logic flow
  • Proper handling of edge cases (returning count or count+1)

5. Efficiency

The solution is efficient for the problem it's solving (Longest Palindrome), using a hash set to track characters and efficiently counting pairs.


FEEDBACK

Strengths:

  • The code is clean, well-documented, and follows good coding practices
  • The algorithm is efficient with O(n) time complexity
  • Edge cases are properly handled (when there's a remaining unpaired character)

Areas for Improvement:

  • Wrong problem: This is the most critical issue. The solution solves "Longest Palindrome" instead of "Contiguous Array". The student may have confused the problem statements.
  • Missing solution: There is no attempt to solve the actual Contiguous Array problem, which typically requires using a hash map to track cumulative sums and find equal counts of 0s and 1s.

The student needs to submit a solution that actually addresses the Contiguous Array problem. The current submission is for a completely different problem and will not pass the test cases for the intended problem.

VERDICT: NEEDS_IMPROVEMENT


Longest Palindrome (subarrysumeqk.py)

  1. Wrong Problem: You submitted a solution for "Subarray Sum Equals K" instead of "Longest Palindrome". Please ensure you're solving the correct problem.

  2. For the Longest Palindrome problem, the correct approach would be:

    • Count the frequency of each character
    • Sum up all pairs (frequency // 2) * 2
    • If there's any character with an odd count, add 1 for the center
  3. Code Quality Note: Your subarray sum solution is well-written with proper variable naming, comments, and follows good practices for that specific problem.

  4. Next Steps: Please implement the correct solution using either:

    • A HashSet approach (add/remove pairs, add 1 if any unpaired remain)
    • A frequency counting approach (count pairs, check for any odd frequency)

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