We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent e59c1ee commit 09517b8Copy full SHA for 09517b8
src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/sherlock_and_anagrams.ts
@@ -20,7 +20,10 @@ export function sherlockAndAnagrams(s: string): number {
20
// Add substrings to a candidate list.
21
// two strings are anagrams if sorted strings are the same.
22
23
- const anagram_candidate = substr.split('').sort().join('');
+ const anagram_candidate = substr
24
+ .split('')
25
+ .sort((a: string, b: string) => a.localeCompare(b))
26
+ .join('');
27
if (anagram_candidate in candidates) {
28
candidates[anagram_candidate].push(substr);
29
} else {
0 commit comments