Tap here to switch tabs
Problem
Submissions

Problem: Minimum Deletions to Make Alternating Substring

Try to solve the Minimum Deletions to Make Alternating Substring problem.

Statement

You are given a string s of length n consisting only of the characters 'A' and 'B', along with a 2D2 D integer array queries.

There are two types of queries:

  • [1, j]: Flip the character s[j]. If s[j] is 'A', it becomes 'B', and if s[j] is 'B', it becomes 'A'.

  • [2, l, r]: Determine the minimum number of character deletions required to make the substring s[l..r] alternating.

A string is defined as alternating if no two adjacent characters are equal.

Return an integer array containing the results of all type 22 queries in the order they appear.

Constraints:

  • 1≤n==1 \leq n == s.length ≤105\leq 10^5

  • s[i] is either 'A' or 'B'.

  • 1≤q==1 \leq q == queries.length ≤105\leq 10^5

  • queries[i].length is equal to 22 or 33.

  • queries[i] is either of the form [1, j] or [2, l, r].

  • 0≤j≤n−10 \leq j \leq n - 1

  • 0≤l≤r≤n−10 \leq l \leq r \leq n - 1

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Deletions to Make Alternating Substring

Try to solve the Minimum Deletions to Make Alternating Substring problem.

Statement

You are given a string s of length n consisting only of the characters 'A' and 'B', along with a 2D2 D integer array queries.

There are two types of queries:

  • [1, j]: Flip the character s[j]. If s[j] is 'A', it becomes 'B', and if s[j] is 'B', it becomes 'A'.

  • [2, l, r]: Determine the minimum number of character deletions required to make the substring s[l..r] alternating.

A string is defined as alternating if no two adjacent characters are equal.

Return an integer array containing the results of all type 22 queries in the order they appear.

Constraints:

  • 1≤n==1 \leq n == s.length ≤105\leq 10^5

  • s[i] is either 'A' or 'B'.

  • 1≤q==1 \leq q == queries.length ≤105\leq 10^5

  • queries[i].length is equal to 22 or 33.

  • queries[i] is either of the form [1, j] or [2, l, r].

  • 0≤j≤n−10 \leq j \leq n - 1

  • 0≤l≤r≤n−10 \leq l \leq r \leq n - 1