The One-Flip Label Audit
A printing hub stamps short labels for warehouse bins. Every label is a lowercase string, and the press occasionally suffers a one-position drift: two plates end up producing labels of the same length that match everywhere except exactly one character. Your lead wants to know whether yesterday's batch contains evidence of such a drift.
Two labels form a one-flip pair when they have equal length and differ at exactly one position. Labels that are perfectly identical came off the same clean plate, so a pair of identical entries never counts as a drift. Labels of different lengths cannot be compared position by position and never qualify either.
Formally, given an array of strings words, return true if there exist indices i != j such that words[i] and words[j] have the same length and differ at exactly one character position, and return false otherwise. The batch may contain repeated labels; repetition by itself is not a drift.
Comparing every pair of labels character by character works but scales poorly. A sharper view groups labels by the parts that surround each candidate flip position, which is where hashing earns its keep.
The One-Flip Label Audit
A printing hub stamps short labels for warehouse bins. Every label is a lowercase string, and the press occasionally suffers a one-position drift: two plates end up producing labels of the same length that match everywhere except exactly one character. Your lead wants to know whether yesterday's batch contains evidence of such a drift.