Skip to content

Completed Hashing 2 course#2182

Open
sanjoli97 wants to merge 2 commits into
super30admin:masterfrom
sanjoli97:master
Open

Completed Hashing 2 course#2182
sanjoli97 wants to merge 2 commits into
super30admin:masterfrom
sanjoli97:master

Conversation

@sanjoli97

Copy link
Copy Markdown

No description provided.

@super30admin

Copy link
Copy Markdown
Owner

Subarray Sum Equals K (SubArraySum.java)

Strengths:

  • Correct algorithm implementation using prefix sum with hash map
  • Clear and informative comments explaining the approach
  • Good variable naming conventions
  • Proper handling of the base case (map.put(0, 1))
  • Clean code structure and formatting

Areas for Improvement:

  • The code performs two hash map lookups when updating the count for an existing running sum. Consider using map.getOrDefault(rsum, 0) + 1 to simplify this:
    map.put(rsum, map.getOrDefault(rsum, 0) + 1);
  • While the current approach works correctly, the reference solution's approach is slightly more concise.

VERDICT: PASS


Contiguous Binary Subarray (ContiguousArray.java)

Strengths:

  • Excellent documentation with time/space complexity comments
  • Clear and descriptive variable names (maxLength, runningSum, map)
  • Proper handling of edge cases (initializing map with (0, -1))
  • Clean, readable code structure
  • Correct algorithm implementation

Areas for Improvement:

  • The solution is already well-optimized. No significant improvements needed.
  • Minor suggestion: Could use map.getOrDefault() for slightly more concise code, but current approach is perfectly fine.

VERDICT: PASS


Longest Palindrome in a string (LongestPallindrome.java)

Strengths:

  • Clean, readable implementation that matches the optimal approach
  • Good use of HashSet for O(1) lookup and removal
  • Well-documented with time and space complexity in comments
  • Proper handling of edge cases (empty set check)

Areas for Improvement:

  • The comment claims O(1) space complexity, but technically the set can grow up to 52 characters. While this is effectively constant, you could clarify this in comments or note it as O(min(n, 52)) or similar.
  • Consider using the return value of set.add(c) to avoid the extra contains() call - this is a minor optimization but demonstrates deeper understanding of HashSet API.

Overall, this is a solid solution that correctly and efficiently solves the problem.

VERDICT: PASS

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