From d088e1810f7ef220f7f4b1cd5ae5d12668faaad0 Mon Sep 17 00:00:00 2001 From: netotz Date: Mon, 13 Jul 2026 12:06:24 -0700 Subject: [PATCH] Correct time complexity and clarify case sensitivity Updated time complexity to reflect that it is O(n) instead of O(n + m) and added clarification on case sensitivity and time complexity. --- articles/is-anagram.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/articles/is-anagram.md b/articles/is-anagram.md index a707d2c54..71d28b1f7 100644 --- a/articles/is-anagram.md +++ b/articles/is-anagram.md @@ -375,7 +375,7 @@ impl Solution { ### Time & Space Complexity -- Time complexity: $O(n + m)$ +- Time complexity: $O(n)$ - Space complexity: $O(1)$ since we have at most $26$ different characters. > Where $n$ is the length of string $s$ and $m$ is the length of string $t$. @@ -603,7 +603,7 @@ impl Solution { ### Time & Space Complexity -- Time complexity: $O(n + m)$ +- Time complexity: $O(n)$ - Space complexity: $O(1)$ since we have at most $26$ different characters. > Where $n$ is the length of string $s$ and $m$ is the length of string $t$. @@ -619,3 +619,7 @@ If two strings have different lengths, they cannot be anagrams. Skipping this ea ### Case Sensitivity Issues When the problem specifies lowercase letters only (as in this problem), case sensitivity is not an issue. However, if the problem allows mixed case, forgetting to normalize to the same case (e.g., converting both strings to lowercase) will cause incorrect results where "Listen" and "Silent" would wrongly be considered non-anagrams. + +### Time Complexity + +If you first check the string lengths and only iterate a single string, the time complexity is $O(n)$, not $O(n + m)$.