FastPrepMinimum Deletions for Unequal Adjacent Characters

Minimum Deletions for Unequal Adjacent Characters

IBM logoIBM● EasyFULLTIMEOA
Learn

Problem statement

You are given an ordered array of printable-ASCII strings. For each string, find the minimum number of character deletions needed so that no two adjacent retained characters are equal. Deletions must preserve the relative order of retained characters.

Return one deletion count per string in input order.

Function

minimumDeletions(strings: String[]) → int[]

Examples

Example 1

strings = ["AABAAB", "AAAA", "ABCD"]return = [2, 3, 0]

The first string needs one deletion from each AA run, the second keeps one of four equal characters, and the third already satisfies the rule.

Example 2

strings = ["", "a", "aabccddd"]return = [0, 0, 4]

Empty and single-character strings need no deletions. The last string deletes one a, one c, and two d characters.

Constraints

  • Every input contains only printable ASCII characters.
  • The total length of all strings is at most 200000.
  • Input order is preserved in the returned counts.

More IBM problems

See IBM hiring insights
public int[] minimumDeletions(String[] strings) {
  // write your code here
}
strings["AABAAB", "AAAA", "ABCD"]
expected[2, 3, 0]
Checking account…