← JavaScript Coding

Valid Anagram

easyblind-75dsastringshashing
Asked at
Amazon
Google
LinkedIn
Meta
Microsoft
Amazon, Google, LinkedIn, Meta, Microsoft

Problem statement

Implement isAnagram for the classic Valid Anagram problem.

This Blind 75 version is framed for frontend interviews: write clean JavaScript, name the invariant out loud, and handle edge cases without over-engineering.

What this tests

  • Pattern: frequency counting.
  • Ability to explain time and space complexity clearly.
  • Careful handling of empty inputs, duplicates, and boundary cases.
  • Production-style JavaScript readability, not just competitive-programming shortcuts.

Requirements & constraints

  • →Use JavaScript without external libraries.
  • →Prefer the standard optimal interview approach for this pattern.
  • →Return deterministic output when multiple valid outputs exist where the prompt implies ordering.

Examples

  • Example 1

    Input: Use the canonical Blind 75 sample for this problem.

    Output: Return the value required by the problem statement.

How to approach Valid Anagram

The strategy an interviewer expects you to reach for.

Anagram checks show up in autocomplete and spelling UIs — same letters, different order. Naive move Sort both strings and compare, or nest count loops. Where it breaks Sorting is fine until strings are huge or you must be O(n). Unicode/case rules matter if the prompt normalizes. The fix Count frequencies (array of 26 or a Map). One string increments, the other decrements; all counts must return to zero. Dry-run: Example: "anagram" vs "nagaram" → counts hit zero; "rat" vs "car" fails on t. Remember: Same multiset of characters — frequency maps, not sorting, when you need linear time. Say this in the interview: I'd count character frequencies for both strings and confirm the maps match.

Premium

The full solution is part of HelloFrontend Pro

The question above is free to read in full. Upgrade to unlock the interactive workspace and the senior-level walkthrough that go with it.

  • Runnable editor with the hidden test suite
  • Progressive hints that unlock as you get stuck
  • Senior-level reference solution with a line-by-line walkthrough
Unlock the full solution →

Already a member? Log in to open the workspace.

More JS Coding questions

View all JS Coding →
JS CodingMedium

Data Merging (Gym Sessions)

JS CodingHard

Data Selection

JS CodingMedium

LRU Cache

JS CodingEasy

Two Sum

JS CodingEasy

Contains Duplicate

JS CodingMedium

Group Anagrams

Explore related prep hubs

  • All JavaScript coding
  • JavaScript interview questions
  • JS polyfill interview questions
  • Debounce & throttle questions
  • React interview hub
  • Amazon interview
  • Google interview
  • LinkedIn interview
  • Meta interview
  • Microsoft interview