A listening post has recorded n encoded transmissions. Every transmission is a string of exactly m lowercase English letters, and all n transmissions share the same length m. For a transmission s, define its cadence as the sequence of m-1 values where the i-th value is the character code of s[i+1] minus the character code of s[i] (treating 'a' through 'z' as consecutive codes, so the sign and size of each step is what matters). It is guaranteed that all n transmissions share exactly the same cadence except for exactly one transmission, whose cadence differs from that common cadence in at least one position. Find and report that one transmission.
n.n lines contains one transmission: a string of exactly m lowercase English letters. All n transmissions have the same length m.Print the one transmission whose cadence differs from the cadence shared by all of the others.
Example 1
Input
3 adc wzy abc
Expected
abc
Explanation
adc has cadence (+3, -1) since d-a=3 and c-d=-1. wzy has the same cadence (+3, -1) since z-w=3 and y-z=-1. abc has cadence (+1, +1), which does not match the shared (+3, -1) cadence of the other two, so abc is the outlier.
Example 2
Input
4 aaa bob ccc ddd
Expected
bob
Explanation
aaa, ccc, and ddd all have cadence (0, 0) since every pair of consecutive letters in each is identical. bob has cadence (+13, -13) since o-b=13 and b-o=-13, which differs from the shared (0, 0) cadence of the other three, so bob is the outlier.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →