Skip to content

solve hashing 2#2184

Open
vvkumaryadla wants to merge 1 commit into
super30admin:masterfrom
vvkumaryadla:solve-hashing-2
Open

solve hashing 2#2184
vvkumaryadla wants to merge 1 commit into
super30admin:masterfrom
vvkumaryadla:solve-hashing-2

Conversation

@vvkumaryadla

Copy link
Copy Markdown

solve hashing 2 problems

@super30admin

Copy link
Copy Markdown
Owner

Subarray Sum Equals K (SubArraysSum.java)

Strengths:

  • Correct implementation of the prefix sum + hashmap technique
  • Clear and descriptive comments explaining the approach
  • Good variable naming (rSumMap, rSum, count)
  • Properly handles edge cases with the initial dummy value (0,1)
  • Same time and space complexity as the reference solution

Areas for Improvement:

  • The map update logic can be simplified using map.put(rSum, map.getOrDefault(rSum, 0) + 1) instead of the if-else block, making the code more concise and idiomatic
  • Consider using an enhanced for-each loop (for (int num : nums)) which is more modern and avoids index bounds issues

VERDICT: PASS


Contiguous Binary Subarray (ContiguousArray.java)

Strengths:

  • Clean, readable implementation that matches the optimal approach
  • Good use of meaningful variable names
  • Helpful inline comment explaining the algorithm
  • Correct handling of edge cases (initializing map with 0 -> -1)

Areas for Improvement:

  • The code is essentially identical to the reference solution, which is good for correctness but could benefit from more distinctive implementation style
  • Consider adding input validation (e.g., null/empty array check) for robustness
  • Could add a brief explanation of why treating 0 as -1 and 1 as +1 works

Overall, this is a solid implementation that demonstrates understanding of the problem and the optimal solution approach.

VERDICT: PASS


Longest Palindrome in a string (longestPalindrome.java)

Strengths:

  • Correct algorithm implementation that handles both paired and unpaired characters
  • Good use of HashSet for O(1) lookup and removal
  • Clean, readable code with descriptive variable names
  • Minor optimization by using charAt() instead of toCharArray()
  • Proper handling of edge cases (single character strings)

Areas for Improvement:

  • The comment stating "Space complexity O(1)" is technically correct for bounded character sets, but could be more precisely stated as O(min(n, σ)) where σ is the character set size
  • Consider using enhanced for-loop (for (char c : s.toCharArray())) for better readability, as shown in the reference solution

The solution is functionally equivalent to the reference solution and demonstrates solid understanding of 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