Optimize Identifiers
Reported by candidates from Amazon's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Amazon's "Optimize Identifiers" hit the OA circuit in November 2024, and it's a string transformation problem that looks deceptively simple. You're likely given a list of variable names or identifiers and asked to optimize them according to some rule: usually case conversion, compression, or collision avoidance. The trap is assuming the optimization rule is obvious. It's not. Read the problem twice before you code, because the edge cases will be in the footnotes.
Pattern and pitfall
This problem typically involves scanning a string or array of identifiers and applying a transformation logic that might be case-insensitive matching, character-frequency rules, or hash-collision mitigation. The common miss is handling unicode, mixed case, or repeated patterns without a clear plan. Your first instinct will be a hash table to track existing identifiers, then a loop to apply the transformation. That's correct. The second instinct should be: what happens if two different inputs optimize to the same output. That's where the problem bites. StealthCoder will spot the edge case you skip in your first pass and feed you the pattern live, so you don't blank on a detail that costs you half your score.
If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.
You can drill Optimize Identifiers 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. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as valid anagram. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass Amazon's OA.
Amazon reuses patterns across OAs. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Optimize Identifiers FAQ
What's the actual optimization rule if the problem statement is vague?+
Read the examples carefully. Amazon usually defines it implicitly: convert to lowercase, remove underscores, or collapse repeated characters. The rule is always in the test cases. If you don't see it in three examples, ask yourself: is it a hash collision problem, not a transformation one.
Is this a hash-table problem or a string problem?+
Both. Use a hash table to track which identifiers have been optimized, then iterate through the input and apply the string transformation to each. You're checking for collisions, so the table matters as much as the string logic.
How do I handle collisions if two identifiers optimize to the same string?+
The problem usually specifies: either reject the collision, append a counter, or return an error. Look for this in the examples before you code. Don't assume. If it's not specified, the test cases won't hit it.
What's the time complexity Amazon expects?+
Linear or O(n*m) where n is the number of identifiers and m is average length. Hash table lookup and string operations are O(1) and O(m). Amazon doesn't ask for exotic optimizations here, so a straightforward loop and hash check will pass.
Will I need regex or fancy string methods?+
Probably not. Most optimizations are simple: lowercase, remove specific chars, collapse whitespace. If the problem needs regex, it will hint hard. Start with basic string slicing and character iteration. Regex is often overkill and slower.