Question Bank

String Anagram and Palindrome

Difficulty: Medium

Five prompts on anagram detection by frequency and palindrome checks via two pointers, with one bug hunt and one canonical implementation.

Question Bank
/

String Anagram and Palindrome

String Anagram and Palindrome

Five prompts on anagram detection by frequency and palindrome checks via two pointers, with one bug hunt and one canonical implementation.

Question Bank
Medium
JavaScript
5 questions
strings
palindrome
two-pointers
interview-prep

1,022 views

33

Implement isAnagram(a, b) returning true if a and b are anagrams of each other. Aim for O(n) time and O(1) extra space (assume lowercase ASCII).

Examples

Example 1:

Input: a = 'listen', b = 'silent'
Output: true
Explanation: Counts increment for a and decrement for b. Every count returns to zero, confirming the two strings have identical character multisets.

Example 2:

Input: a = 'foo', b = 'bar'
Output: false
Explanation: After the increment / decrement sweep, several counts are non-zero, so the strings are not anagrams.