FastPrepMax Number of Operations
Problems/Max Number of Operations

Max Number of Operations

Salesforce logoSalesforce● HardOA

Updated Sep 2026

QuestionFunctionExamples

Problem statement

Given a string s, choose 3 consecutive characters s[i], s[i+1], s[i+2]. Replace s[i+2] with s[i] if s[i]=s[i+1] and s[i+1]≠s[i+2]. Find the maximum number of operations that can be performed on s.

Function

maxNumberOfOperations(s: String) → int

Examples

Example 1

s = "accept"return = 3

:3

Example 2

s = "aabaab"return = 2

:o

Example 3

s = "aabba"return = 4

:)

More Salesforce interview questions

  • Count Subarrays With Product Equal to KOA · Seen Nov 2026
  • Get Minimum TimeOA · Seen Nov 2026
  • Count Increasing TripletsONSITE INTERVIEW · Seen Nov 2026
  • Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2026
  • Reverse a Sublist of a Linked ListONSITE INTERVIEW · Seen Nov 2026
  • Rotting OrangesONSITE INTERVIEW · Seen Nov 2026
  • 3Sum SmallerONSITE INTERVIEW · Seen Nov 2026
  • Count Zero Request ServersONSITE INTERVIEW · Seen Nov 2026
  • Minimum No-Repeat Segments After One Character RemovalOA · Seen Nov 2026
  • Get Message StatusOA · Seen Nov 2026

Similar questions at other companies

  • Word Wrap with Even JustificationSentry · OA · PHONE SCREENSentry interview questions
  • Robot Assembly Line ConflictsGoogle · OAGoogle interview questions
  • Minimum Steps on a Circular Letter DialIBM · OAIBM interview questions
  • Format a Centered Newspaper PageVisa · OAVisa interview questions
  • Balance the Game BoardMicrosoft · OAMicrosoft interview questions
  • Text JustificationUber · PHONE SCREENUber interview questions
  • Choose the Next Hidden-Word GuessFlexport · ONSITE INTERVIEWFlexport interview questions
  • Choose the Next Hidden-Word GuessCharacter.AI · PHONE SCREEN
  • URL Segment Compression Part 3 — Global Token BudgetStripe · ONSITE INTERVIEWStripe interview questions
  • Lexicographically Largest IdentifierAmazon · OA

Salesforce interview experiences

  • Salesforce Infrastructure SWE OA and Onsite: 1 Experience
  • Salesforce Experienced Backend SWE First Round: 1 Experience
All Salesforce interview questionsSee Salesforce hiring insights
Saved
class Solution {
    public int maxNumberOfOperations(String s) {
      // write your code here
    }

}
Checking account…