Skip to content

Commit 9e4909c

Browse files
contents/algorithms: fix incorrect time complexity for anagrams (#692)
Co-authored-by: Atharva <[email protected]>
1 parent 3d61290 commit 9e4909c

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

apps/website/contents/algorithms/string.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ An anagram is word switch or word play. It is the result of rearranging the lett
9595

9696
To determine if two strings are anagrams, there are a few approaches:
9797

98-
- Sorting both strings should produce the same resulting string. This takes O(n.log(n)) time and O(log(n)) space.
98+
- Sorting both strings should produce the same resulting string. This takes O(n.log(n)) time and O(n) space.
9999
- If we map each character to a prime number and we multiply each mapped number together, anagrams should have the same multiple (prime factor decomposition). This takes O(n) time and O(1) space. Examples: [Group Anagram](https://leetcode.com/problems/group-anagrams/)
100100
- Frequency counting of characters will help to determine if two strings are anagrams. This also takes O(n) time and O(1) space.
101101

0 commit comments

Comments
 (0)