Reported September 2026
Wayfairbit manipulation

Assign Distinct Letter Values to Minimize XOR

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

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

The 100,000-character string in this Wayfair OA, reported September 2026, is a decoy. The real input is at most 26 distinct letters, each mapped to a value in 0-100, and trying every assignment is hopeless. The twist is that XOR cancels pairs, so the string collapses to one question about the odd-frequency letters. It's a bit-manipulation problem wearing a counting costume. Read the canonical output rule twice, because the lexicographic tie-break is where candidates lose points. If you blank on the construction under the clock, StealthCoder is the invisible safety net that reads the problem on screen and hands you a working approach. Know the collapse trick first and the rest is small.

The problem

You are given a non-empty lowercase string s. Assign a distinct integer in [0,100] to every distinct letter.
The mapped XOR is the bitwise XOR of the assigned value for every character occurrence in s. Minimize that XOR.
Canonical Output
List the odd-frequency letters in alphabetical order, followed by the even-frequency letters in alphabetical order. Return their assigned values in that order. Among all minimum-XOR assignments, use the lexicographically smallest increasing value sequence for the odd-frequency letters. Then assign each even-frequency letter the smallest value not already used.

Function
assignLetterValues(s: String) → int[]

Examples
Example 1
s = "abbccc"
return = [0,1,2]
The odd-frequency letters are a,c, and 0 XOR 1 = 1 is the minimum possible XOR for two distinct values. Even-frequency b receives the smallest unused value, 2.
Example 2
s = "aabb"
return = [0,1]
Both letters occur an even number of times, so the mapped XOR is already 0. They receive the smallest distinct values.

Constraints
1 <= s.length <= 100000
s contains only lowercase English letters.

Reported by candidates. Source: FastPrep

Pattern and pitfall

Count letter frequencies. Every even-frequency letter contributes its value an even number of times, so it cancels. Only the k odd-frequency letters affect the XOR. So the task is to pick k distinct values from 0-100, in increasing order, with minimum XOR, and lexicographically smallest among ties. Don't hardcode cases. Run a DP over (position, last value, current XOR) with XOR below 128, then reconstruct greedily by picking the smallest next value that can still reach the best XOR. That state space is tiny. The pitfall is the ordering rule: the values are increasing across the odd letters in alphabetical order, so you can't pick freely. Another trap is assigning even letters first, which steals small values. Assign them last, each the smallest unused value. If the reconstruction logic jams during the live OA, StealthCoder is the hedge that can supply the DP skeleton without the proctor seeing it.

If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.

If this hits your live OA

You can drill Assign Distinct Letter Values to Minimize XOR 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 StealthCoder

Related leaked OAs

⏵ The honest play

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

Wayfair 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.

Assign Distinct Letter Values to Minimize XOR FAQ

What's the real trick in this Wayfair OA question?+

XOR cancels pairs, so even-frequency letters never matter for the total. Only odd-frequency letters count. After that, the problem becomes choosing k distinct increasing values in 0-100 that minimize their XOR. The 100000 length is irrelevant beyond counting letters.

How hard is it really?+

Medium. The idea is short, but the canonical output rule adds bookkeeping. Most mistakes come from the tie-break and from assigning even letters in the wrong order, not from the XOR logic itself.

Can I just brute force the assignments?+

No. Choosing up to 26 distinct values from 101 gives an astronomically large search space. Use a DP over position, last chosen value and running XOR. XOR stays under 128, so the state count is small and fast.

How do I get the lexicographically smallest sequence?+

First compute the minimum achievable XOR with the DP. Then rebuild the answer left to right, choosing the smallest value greater than the previous one from which the remaining letters can still reach that minimum. Check against both examples.

How do I prepare for this in 48 hours?+

Practice frequency counting plus XOR cancellation, then write one small DP with a reachability table and a greedy reconstruction. Test edge cases: all letters even, a single odd letter, and exactly two odd letters, where the answer is 0 and 1.

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

OA at Wayfair?
Invisible during screen share
Get it