FastPrepTransform String
Problems/Transform String

Transform String

Jane Street logoJane Street● MediumOA

Updated Sep 2026

QuestionFunctionExamples

Problem statement

A string S consisting of the letters A, B, C and D is given. The string can be transformed either by removing a letter A together with an adjacent letter B, or by removing a letter C together with an adjacent letter D.

Write a function:

string solution(string &S);

that, given a string S consisting of N characters, returns any string that:

  • can be obtained from S by repeatedly applying the described transformation, and
  • cannot be further transformed.

If at some point there is more than one possible way to transform the string, any of the valid transformations may be chosen.

Write an efficient algorithm for the following assumptions:

  • the length of string S is within the range [0..250,000];
  • string S is made only of the following characters: 'A', 'B', 'C', and/or 'D'.

Function

solution(S: String) → String

Examples

Example 1

S = "CBACD"return = "C"
Example 1 illustration

One of the possible sequences of operations is as follows: CBACD -> CBA -> C

Example 2

S = "CABABD"return = ""
Example 2 illustration

One possible sequence of operations is: CABABD -> CABD -> CD -> (empty string)

Example 3

S = "ACBDACBD"return = "ACBDACBD"

No operation can be applied to string S, so the function should return "ACBDACBD".

More Jane Street interview questions

  • Maximum-Scoring Consecutive Tree LevelsPHONE SCREEN · Seen Nov 2026
  • Tree Selection and VisibilityPHONE SCREEN · Seen Nov 2026
  • Load/Store Arithmetic InterpreterPHONE SCREEN · Seen Oct 2026
  • Instrument Stack Language JumpsPHONE SCREEN · Seen Oct 2026
  • Run a Stack Language InterpreterPHONE SCREEN · Seen Oct 2026
  • Code Editor FoldingONSITE INTERVIEW · Seen Oct 2026
  • Positive-Integer Expression EvaluationPHONE SCREEN · Seen Oct 2026
  • Exact-Sixty Dice Game ValueONSITE INTERVIEW · Seen Oct 2026
  • Expected Value of Modified DiceONSITE INTERVIEW · Seen Oct 2026
  • Spaceship Equipment LoadoutONSITE INTERVIEW · Seen Oct 2026

Similar questions at other companies

  • Basic Calculator IITypeSafe AI · OA
  • Compress Editor Actions into Operational Transform OperationsReplit · OA · PHONE SCREEN · ONSITE INTERVIEW
  • Substring RemovalJP Morgan Chase · OAJP Morgan Chase interview questions
  • Decode StringAbridge · OAAbridge interview questions
  • Nested Recipe Blocks (Game Adaptation)Roblox · OARoblox interview questions
  • Minimum Remaining LengthWells Fargo · OA · PHONE SCREENWells Fargo interview questions
  • Modify the StringYahoo · OAYahoo interview questions
  • Maximum Score in Balanced String 🍇Amazon · OA
  • Lexicographically Minimum Stack EncryptionRippling · OARippling interview questions
  • Shortest String After Erasing Equal PairsMarshall Wace · OAMarshall Wace interview questions

Jane Street interview experiences

  • Jane Street TDO UK and Hong Kong: 22 Experiences (Part 10 of 10)
  • Jane Street TDOE US Final Round: 11 Experiences (Part 5 of 10)
  • Jane Street TDO Phone Math Round: 26 Experiences (Part 9 of 10)
  • Jane Street TDOE UK Phone Screen: 15 Experiences (Part 4 of 10)
  • Jane Street TDO Excel and VBA Test: 23 Experiences (Part 8 of 10)
  • Jane Street TDOE UK Coding Round: 15 Experiences (Part 3 of 10)
All Jane Street interview questionsSee Jane Street hiring insights
Saved
class Solution {
    public String solution(String S) {
      // write your code here
    }

}
Checking account…