FastPrepValid Anagram
Problems/Valid Anagram

Valid Anagram

Microsoft logoMicrosoft● EasyINTERNONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a review of a Microsoft software engineering internship. A quick anagram test on two strings was used as a warm-up. The same review also mentions an LRU cache question. The steps were a take-home test followed by an online day with three interviews. The review does not say at which step the anagram test came up.

The review gives no limits or character set. Here you get two lowercase strings of up to 5 * 10^4 letters. Return true when one is a rearrangement of the other (same letters, same counts). Otherwise return false.

Our version is about 95% the same as the reported question.

Given two strings s and t, return true if t is an anagram of s, and false otherwise.

An anagram uses exactly the same letters as the original, each the same number of times, in any order.

Function

isAnagram(s: String, t: String) → boolean

Examples

Example 1

s = "listen"t = "silent"return = true

Both strings use the letters e, i, l, n, s and t once each, so t is a rearrangement of s.

Example 2

s = "rat"t = "car"return = false

s has an r, an a and a t; t has a c in place of the t, so the answer is false.

Example 3

s = "aab"t = "abb"return = false

Both strings use only a and b, but s has two a's and t has one. The counts must match, so the answer is false.

Constraints

  • 1 <= s.length, t.length <= 5 * 10^4
  • s and t consist of lowercase English letters.

More Microsoft Onsite Interview questions

  • Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2026
  • Valid ParenthesesONSITE INTERVIEW · Seen Nov 2026
  • Count a User's Actions in an Event LogONSITE INTERVIEW · Seen Nov 2026
  • Smallest Batch Size Within a Step LimitONSITE INTERVIEW · Seen Nov 2026
  • Count Subarrays with Equal Even and Odd CountsONSITE INTERVIEW · Seen Nov 2026
  • Minimum Time to Rot All OrangesONSITE INTERVIEW · Seen Nov 2026
  • Coin ChangeONSITE INTERVIEW · Seen Oct 2026
  • Daily USD Totals with Effective-Dated Exchange RatesONSITE INTERVIEW · Seen Oct 2026
  • Number Words to Digits in Any LanguageONSITE INTERVIEW · Seen Oct 2026
  • Totals from a Tiered Rate TableONSITE INTERVIEW · Seen Oct 2026

Similar questions at other companies

  • Count Adjacent Symbol Pairs for BPEAmazon · ONSITE INTERVIEW
  • Map and Accumulate Learning QueriesPalantir · ONSITE INTERVIEWPalantir interview questions
  • Deduplicate Logs: Keep FirstGoogle · ONSITE INTERVIEWGoogle interview questions
  • Check AnagramsDeloitte · ONSITE INTERVIEWDeloitte interview questions
  • Check AnagramsBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • Check Anagram Pairs Index by IndexExpedia · ONSITE INTERVIEWExpedia interview questions
  • Recursive Character FrequencyPalo Alto Networks · ONSITE INTERVIEWPalo Alto Networks interview questions
  • Valid AnagramMotive · ONSITE INTERVIEWMotive interview questions
  • Anagram Words in a SentenceNutanix · ONSITE INTERVIEWNutanix interview questions
  • List Each Name Once, AlphabeticallyDocuSign · ONSITE INTERVIEWDocuSign interview questions

Interview reports that mention this question

  • Microsoft SWE Intern, Early 2025: 41 Experiences (Part 5 of 6)
  • Microsoft SWE Intern Interviews: 244 Experiences (Part 1 of 6)

Microsoft interview experiences

  • Microsoft Explore and Student SWE: 12 Experiences (Part 6 of 6)
  • Microsoft SWE Intern, Mid 2025: 42 Experiences (Part 4 of 6)
  • Microsoft SWE Intern, Late 2025: 47 Experiences (Part 3 of 6)
  • Microsoft SWE Intern, Early 2026: 54 Experiences (Part 2 of 6)
All Microsoft interview questionsSee Microsoft hiring insights
Saved
class Solution {
    public boolean isAnagram(String s, String t) {
        // Write your code here.
    }
}
Checking account…