Skip to content

completed hashing - 1 - #2305

Open
yashhh-23 wants to merge 1 commit into
super30admin:masterfrom
yashhh-23:master
Open

completed hashing - 1#2305
yashhh-23 wants to merge 1 commit into
super30admin:masterfrom
yashhh-23:master

Conversation

@yashhh-23

Copy link
Copy Markdown

No description provided.

@super30admin

Copy link
Copy Markdown
Owner

Grouping Anagrams Together (isomorphicStrings.java)

  • Strengths: The code is clean, well-commented, and handles edge cases properly (length mismatch). The logic for checking bidirectional mapping is correct for the isomorphic strings problem.
  • Areas for Improvement:
    1. The solution addresses the wrong problem entirely. You need to group anagrams together, not check if two strings are isomorphic.
    2. For the anagram grouping problem, consider using a sorted string as a key (e.g., sort each string and use it as a map key) or counting character frequencies.
    3. The method should return a collection of grouped anagrams, not a boolean.
    4. Read the problem description carefully to ensure you're solving the right problem.

VERDICT: NEEDS_IMPROVEMENT


Isomorphic Strings (problem1.java)

Strengths:

  • The code is well-structured and readable
  • Good use of HashMap methods (getOrDefault)
  • Clear variable naming and logic flow
  • Proper handling of edge cases (returning '\0')

Critical Issues:

  1. Wrong Problem: You solved "First Unique Character" instead of "Isomorphic Strings". These are completely different problems.
  2. Missing Input: The solution only takes one string parameter, but the problem requires two strings (s and t).
  3. Wrong Algorithm: The isomorphic strings problem requires comparing two strings character-by-character and maintaining bidirectional mappings.

To fix this, you need to:

  1. Accept two string parameters (s and t)
  2. Use two HashMaps to track mappings in both directions
  3. Iterate through both strings simultaneously
  4. Check if the mapping is consistent (no two chars in s map to the same char in t, and vice versa)
  5. Return true only if all mappings are valid

VERDICT: NEEDS_IMPROVEMENT


Word Pattern (problem3.java)

Strengths:

  • Clean, readable code with good variable naming
  • Correct overall algorithm logic
  • Good use of comments explaining the approach
  • Proper handling of edge cases (length mismatch)

Areas for Improvement:

  • The map.containsValue(w) check has O(n) time complexity, making the solution O(n²) in worst case. Consider using a second HashMap (word→char) like the reference solution for O(1) lookups.
  • Could use HashMap<Character, String> with putIfAbsent() for cleaner code
  • The single-map approach is clever but less efficient than the two-map approach

Suggested Optimization:
Use two HashMaps (char→word and word→char) as in the reference solution. This ensures O(1) average time complexity for all operations instead of O(n) for the value check.

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