FastPrepRemove Excess Consecutive Characters
Problems/Remove Excess Consecutive Characters

Remove Excess Consecutive Characters

DRW logoDRW● EasyINTERNOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Our version is about 99% the same as the reported question.

Given a lowercase string S, delete the minimum possible number of characters so that the result contains no three identical consecutive characters.

Return the resulting string. Characters that remain must keep their original relative order.

Function

solution(S: String) → String

Examples

Example 1

S = "eedaaad"return = "eedaad"

Deleting one a leaves no run longer than two.

Example 2

S = "xxxtxxx"return = "xxtxx"

Each run of three x characters loses one character.

Example 3

S = "uuuuxaaaaxuuu"return = "uuxaaxuu"

Each maximal run is shortened independently to at most two characters.

Constraints

  • S.length <= 200000.
  • S contains only lowercase English letters.

More DRW Online Assessment questions

  • Count Balanced Nodes in a Rooted TreeOA · Seen Sep 2026
  • Largest Number With Even Digit FrequenciesOA · Seen Sep 2026
  • Shortest Path Around Rectangular ObstaclesOA · Seen Sep 2026
  • 2020 Account Balance with Monthly Card FeesOA · Seen Aug 2026
  • Nested In-Memory Database TransactionsOA · Seen Aug 2026
  • Password Requirement CheckOA · Seen Aug 2026
  • Last Round for Each PlayerOA · Seen Jul 2026
  • Shortest Compressed Length After RemovalOA · Seen Jul 2026
  • Doctor Appointment Slot AssignmentOA · Seen Jul 2026
  • Maximum Even-Sum Neighboring PairsOA · Seen Jul 2026

Similar questions at other companies

  • Maximum Ones After K OperationsGoldman Sachs · OAGoldman Sachs interview questions
  • Minimum Operations to Reduce a Transaction LedgerVisa · OAVisa interview questions
  • Prepare NotificationMicrosoft · OAMicrosoft interview questions
  • Minimum Changes for Distinct Adjacent CharactersHeadlands Technologies · OAHeadlands Technologies interview questions
  • Minimum Replacements for Unequal Adjacent CharactersIBM · OAIBM interview questions
  • Crop Text at a Whole-Word BoundaryAmerican Express · OAAmerican Express interview questions
  • Minimum Flips for Even Binary RunsJP Morgan Chase · OAJP Morgan Chase interview questions
  • Missing WordsVanguard · OAVanguard interview questions
  • Digit Changes for a Multiple of 9Nutanix · OANutanix interview questions
  • Smallest String After at Most One DeletionLSEG · OALSEG interview questions
All DRW interview questionsSee DRW hiring insights
Saved
class Solution {
    public String solution(String S) {
        // Write your code here.
    }
}
Checking account…