Odd String Difference

You are given an array of equal-length strings words. Assume that the length of each string is n.

Each string words[i] can be converted into a difference integer array difference[i] of length n - 1, where difference[i][j] = words[i][j+1] - words[i][j] for 0 <= j <= n - 2. The difference between two letters is the difference between their positions in the alphabet: the position of 'a' is 0, 'b' is 1, and 'z' is 25.

All the strings in words have the same difference integer array, except one. Find that string.

Return the string in words that has the different difference integer array.

Example 1
Inputwords = ["adc","wzy","abc"]
Output"abc"
The odd array out is [1, 1], so we return the corresponding string, "abc".
Example 2
Inputwords = ["aaa","bob","ccc","ddd"]
Output"bob"
All the integer arrays are [0, 0] except for "bob", which corresponds to [13, -13].

Constraints

  • 3 <= words.length <= 100
  • n == words[i].length
  • 2 <= n <= 20
  • words[i] consists of lowercase English letters.

Asked at 4 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate