Problem · Array

Unique Difference Pattern

Learn this problem
EasyMicrosoftOA
See Microsoft hiring insights

Problem statement

You are given a list of strings containing only uppercase English letters.

All strings in the list have the same length.

For each string, calculate the difference between adjacent letters based on their alphabetical positions.

  • For example, 'B' - 'A' = 1, 'C' - 'A' = 2.
  • These differences form a difference pattern for the string.
  • In the list, all strings except one share the same difference pattern.

Identify and return the string with the unique difference pattern.

Function

findUniqueDifferencePattern(series: String[]) → String

Examples

Example 1

series = ["ACB", "BDC", "CED", "DEF"]return = "DEF"

Calculate the differences between adjacent letters:

  • "ACB": (C - A, B - C) = (+2, -1)
  • "BDC": (D - B, C - D) = (+2, -1)
  • "CED": (E - C, D - E) = (+2, -1)
  • "DEF": (E - D, F - E) = (+1, +1)

The first three strings have the same difference pattern (+2, -1), while "DEF" has a different pattern (+1, +1).

Constraints

  • 3 <= size of series[] <= 26
  • 2 <= length of series[i] <= 26
  • All strings are uppercase English letters only.
  • Within a test case, all strings are of equal length.

More Microsoft problems

drafts saved locally
public String findUniqueDifferencePattern(String[] series) {
  // write your code here
}
series["ACB", "BDC", "CED", "DEF"]
expected"DEF"
checking account