Skip to content

Hashing 2:Completed 3 problems - #2204

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

raninagare wants to merge 1 commit into
super30admin:masterfrom
raninagare:master

Conversation

@raninagare

Copy link
Copy Markdown

No description provided.

@super30admin

Copy link
Copy Markdown
Owner

Subarray Sum Equals K (SubArraySumK.java)

Strengths:

  • Your solution is correct and uses the optimal approach for this problem
  • Excellent comments that explain the mathematical reasoning behind the algorithm — this shows deep understanding
  • Clean variable naming and logical structure
  • Proper handling of the edge case (initial (0, 1) entry in the map)

Areas for Improvement:

  1. Simplify the map update: Replace your three-line map update with a single line using getOrDefault:

    map.put(rSum, map.getOrDefault(rSum, 0) + 1);

    This is more concise, idiomatic Java, and slightly more efficient.

  2. Class naming convention: For LeetCode submissions, the class is typically expected to be named Solution. While your naming is descriptive, it may cause submission issues on the platform.

  3. Consider using HashMap directly: Since you don't need ordering or any special Map features, declaring the variable as HashMap<Integer, Integer> (rather than Map<Integer, Integer>) is fine and slightly more explicit about the implementation choice.

  4. Minor style: The comment block at the top is good practice for documenting complexity and approach — keep doing this!

VERDICT: PASS


Contiguous Array (ContinuousSubArray.java)

The student's solution is essentially identical to the reference solution in terms of approach and implementation. Let me analyze each criterion:

  1. Correctness: The solution correctly solves the problem. It uses the running sum pattern where:

    • 0 decrements the running sum by 1
    • 1 increments the running sum by 1
    • If two indices have the same running sum, the subarray between them is balanced (equal 0s and 1s)
    • The initial entry of (0, -1) handles the edge case where the balanced subarray starts from index 0
    • The solution correctly tracks the maximum length
  2. Time Complexity: O(n) - matches the reference solution. Single pass through the array.

  3. Space Complexity: O(n) - matches the reference solution. Uses a HashMap to store running sums.

  4. Code Quality:

    • The code is well-structured and readable
    • Good comments explaining the approach
    • The class name is slightly different ("ContinuousSubArray" vs "Solution") but this is acceptable
    • The comments at the top provide a clear explanation of the approach
    • The logic flow is clear
  5. Eiviency: The solution is optimal. No further optimizations needed.

The student's solution is functionally identical to the reference solution with the same approach, time complexity, and space complexity.

FEEDik:
Your solution is excellent! It correctly implements the optimal approach for this problem. Here are some observations:

Strengths:

  • Correctly identified and implemented the running sum pattern
  • Properly handled the edge case by initializing the map with (0, -1)
  • Clean, readable code with helpful comments
  • Optimal time and space complexity
  • Good explanation of the approach in the comments

Minor suggestions for improvement:

  • Consider adding more inline comments to explain specific parts of the logic (e.g., why we decrement for 0 and increment for 1)
  • The class name "ContinuousSubArray" differs from the typical "Solution" naming convention used in LeetCode, but this is a minor stylistic point
  • You could add a brief explanation of why the running sum approach works (equal 0s and 1s means the sum returns to the same value)

Overall: This is a well-implemented solution that demonstrates a strong understanding of the problem and the optimal approach. Great work!

VERDICT: PASS


Longest Palindrome (LongestPalindrome.java)

Your solution is correct and well-structured! Here are some observations:

Strengths:

  • Correct logic that matches the reference solution
  • Good time complexity O(n) and space complexity O(1)
  • Nice comments explaining the approach
  • Proper handling of edge cases (null/empty string)
  • Clean and readable code

Minor suggestions:

  • Consider using Set<Character> with explicit type parameter for better readability: Set<Character> set = new HashSet<>();
  • The class name should ideally be Solution to match the expected interface, though this depends on the platform
  • You could use enhanced for loop for cleaner iteration: for (char ch : s.toCharArray())

Overall, this is a solid solution that demonstrates good 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