Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incomplete solution for Valid Anagrams problem #11

Open
gurunathsane opened this issue Oct 5, 2023 · 2 comments
Open

Incomplete solution for Valid Anagrams problem #11

gurunathsane opened this issue Oct 5, 2023 · 2 comments

Comments

@gurunathsane
Copy link
Contributor

In Valid Anagrams problem. the solution is not complete.
it is checking that frequencyCount1 is matching with frequencyCount2 but we also need to test frequencyCount2 is matching with frequencyCount1. for example: if I run the test with const result = validAnagrams('app', 'ppax'); it returns true but it should be false.

@diegodesouza
Copy link

the test expect(validAnagrams('aaa', 'aaab')).toBe(false); is also failing even after proposed solution.

@diegodesouza
Copy link

The issue in this case, with the provided solution is that the length of the freqCount1 is less than freqCount2 or str1 less than str2 where the iteration in this test case ( expect(validAnagrams('aaa', 'aaab')).toBe(false); ) would stop at aaa making it true, the same is happening with your issue. app is the same as ppa since it never gets to x. Does that make sense?

  return Object.keys(str1.length > str2.length ? freqCount1 : freqCount2).every(
        (char) => freqCount1[char] === freqCount2[char]
    );

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

No branches or pull requests

2 participants