Valid Anagram
Updated
Problem statement
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) → booleanExamples
Example 1
s = "listen"t = "silent"return = trueBoth 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 = falses 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 = falseBoth 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^4sandtconsist 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