Reported September 2026
Googlehash table

Best Anagram Match

Reported by candidates from Google's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Google OA. Under 2s to a working solution.
Founder's read

The trap in Google's Best Anagram Match, reported in September 2026, is the input size, not the idea. Checking every candidate by sorting it looks fine on the examples and falls apart when the target and the list both hit 10^5. You need to return the lexicographically smallest exact anagram, or an empty string if nothing matches. It's a hash-table and counting problem wearing an easy costume. If you blank mid-assessment, StealthCoder runs invisibly on your desktop and hands you the approach in real time, but the pattern below is short enough to carry in your head.

The problem

Given a lowercase target string and a list of lowercase candidate words, return the lexicographically smallest candidate that is an exact anagram of the target.
An exact anagram has the same length and the same character frequencies. Return the empty string when no candidate qualifies.

Function
findBestAnagram(target: String, candidates: String[]) → String

Examples
Example 1
target = "listen"
candidates = ["silent","enlist","google"]
return = "enlist"
Both silent and enlist are anagrams; enlist is lexicographically smaller.
Example 2
target = "abc"
candidates = ["ab","abd"]
return = ""
No candidate has the same multiset.

Constraints
1 <= target.length <= 10^5.
0 <= candidates.length <= 10^5.
All strings contain lowercase English letters.

Reported by candidates. Source: FastPrep

Pattern and pitfall

Build a frequency count of the target, 26 slots. For each candidate, skip it immediately if its length differs from the target's. Otherwise compare its counts to the target's, and if they match, keep it if it's smaller than your current best. Use a plain string comparison for the minimum. The pitfall is sorting every candidate, which costs O(L log L) each and can blow up when strings are long. Counting keeps each check linear in its length. Watch the edge cases: an empty candidates list returns an empty string, and a candidate with the same letters but a different length (like "ab" against "abc") must fail. Also don't forget that identical strings count as anagrams. Total work is bounded by the sum of candidate lengths. If the live OA freezes your head, StealthCoder is the hedge that surfaces this exact approach while you type.

Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.

If this hits your live OA

You can drill Best Anagram Match cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made for the candidate who got the OA invite this morning and has 72 hours, not six months.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass Google's OA.

Google reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Best Anagram Match FAQ

How hard is Best Anagram Match really?+

Easy to medium. The logic is a frequency comparison plus a running minimum. What makes it feel harder is the 10^5 bounds, which punish sorting every candidate. If you count letters and filter by length first, it's a short function.

What's the trick to get the lexicographically smallest answer?+

Don't sort the candidates up front. Scan once, and whenever a candidate is a valid anagram, compare it to your stored best and replace it if it's smaller. Start with a null or empty best so the no-match case returns an empty string naturally.

Should I sort each word or use a count array?+

Use a count array of 26. Sorting each word costs L log L and adds up across 10^5 candidates. Counting is linear per word. Sorting works on small inputs, but the constraints here are built to make it risky.

What edge cases should I test before submitting?+

Test an empty candidates list, a candidate shorter or longer than the target, a candidate identical to the target, duplicates in the list, and a single-character target. Example 2 shows a length mismatch must return an empty string, so check that explicitly.

How do I prepare for this in 48 hours?+

Write the counting solution from scratch twice, once with a 26-slot array and once with a hash map. Then practice the group-anagrams style of problem so frequency keys feel automatic. Time yourself on edge cases, since that's where Google-style OAs trip people up.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Google.

OA at Google?
Invisible during screen share
Get it