FastPrepMaximum String Operations
Problems/Maximum String Operations

Maximum String Operations

Microsoft logoMicrosoft● MediumINTERNNEW GRADOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Microsoft online assessment. Our version is about 99% the same as the reported question.

Special thanks: 🌷 A special thank you to a lovely, amazing fren who shared that this question appeared again on November 19, 2026! (˶˃ ᵕ ˂˶) .ᐟ.ᐟ 💜

Given a string s of lowercase English characters, the following operation can be performed any number of times:

Choose three consecutive characters s[i], s[i+1] and s[i+2] where (1 ≤ i ≤ |s| - 2, 1-based indexing) such that s[i] = s[i+1] and s[i+1] ≠ s[i+2]. Replace s[i+2] with s[i].

Find the maximum number of operations that can be applied to s.

Function

getMaximumOperations(s: String) → long

Examples

Example 1

s = "accept"return = 3

The following operations are performed (bold indicates changed character):

  1. Start at i = 2, "cce": The new string s' = "acccpt".
  2. Start at i = 3, s' = "acccct".
  3. Start at i = 4, s' = "accccc".

No other selections are available. The operation can be applied a maximum of 3 times.

Constraints

  • 3 ≤ length of s ≤ 2 * 10^5
  • The string s only contains lowercase English letters.

More Microsoft Online Assessment questions

  • Authentication SystemOA · Seen Nov 2026
  • Minimum Cost to Process Priority TasksOA · Seen Nov 2026
  • Most Visited Sprint MarkerOA · Seen Nov 2026
  • Maximum Escape Game ScoreOA · Seen Nov 2026
  • Count Subarrays with a Perfect-Square ProductOA · Seen Nov 2026
  • Maximum Interactive Team SizeOA · Seen Nov 2026
  • Maximize Pipeline Throughput Under a Scaling BudgetOA · Seen Nov 2026
  • Minimum Cost K-Capable ModelsOA · Seen Nov 2026
  • Find Available Meeting RoomsOA · Seen Oct 2026
  • Maximum Sum of a K-StarOA · Seen Oct 2026

Similar questions at other companies

  • Minimum No-Repeat Segments After One Character RemovalSalesforce · OASalesforce interview questions
  • Longest Non-Decreasing Substring After Pair SwapsVisa · OAVisa interview questions
  • Minimum Deletion Cost for Distinct Adjacent CharactersHSBC · OAHSBC interview questions
  • Minimum Binary Swaps to a PalindromeAT&T · OAAT&T interview questions
  • Robot Assembly Line ConflictsGoogle · OAGoogle interview questions
  • Substring RemovalJP Morgan Chase · OAJP Morgan Chase interview questions
  • Minimum Additions to Make a Valid ABC StringIBM · OAIBM interview questions
  • Maximize Workday EarningsCitadel · OA · PHONE SCREEN · ONSITE INTERVIEWCitadel interview questions
  • Minimum Adjacent TranspositionsEpic · OAEpic interview questions
  • Return Exact Cash Register ChangeBank of America · OABank of America interview questions

Microsoft interview experiences

  • Microsoft OA Questions, October 2026: 4 Experiences
  • Microsoft Experienced SWE Phone Screen: 1 Experience
  • Microsoft Explore and Student SWE: 12 Experiences (Part 6 of 6)
  • Microsoft SWE Intern, Early 2025: 41 Experiences (Part 5 of 6)
  • Microsoft SWE Intern, Mid 2025: 42 Experiences (Part 4 of 6)
  • Microsoft SWE Intern, Late 2025: 47 Experiences (Part 3 of 6)
All Microsoft interview questionsSee Microsoft hiring insights
Saved
class Solution {
    public long getMaximumOperations(String s) {
      // Write your code here.
    }

}
Checking account…