FastPrepTransform a String with at Most One Operation
Problems/Transform a String with at Most One Operation

Transform a String with at Most One Operation

LSEG logoLSEG● EasyFULLTIMEOA

Updated Oct 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The insertion, swap and replacement operations match the report at about 70%. The report omits the operation budget; this exercise uses at most one operation, permits any two-position swap, and allows empty lowercase strings.

Determine whether s can become t using at most one of these operations:

  • Insert one lowercase letter at any position in s, including either end.
  • Replace one character of s with a lowercase letter.
  • Swap the characters at any two distinct positions in s; the positions need not be adjacent.

You may also use no operation. Deletion is not allowed. Return true exactly when the transformation is possible.

Function

canTransformOnce(s: String, t: String) → boolean

Examples

Example 1

s = "abcd"t = "dbca"return = true

Swap positions 0 and 3 in abcd to obtain dbca in one operation.

Example 2

s = "abc"t = "abxc"return = true

Insert x between b and c.

Example 3

s = "abc"t = "ac"return = false

The target is shorter, but deletion is not an allowed operation.

Constraints

  • 0 <= s.length <= 100000.
  • 0 <= t.length <= 100000.
  • s and t contain only lowercase English letters.

More LSEG Online Assessment questions

  • Count Times Using at Most Two DigitsOA · Seen Jul 2025
  • Maximum Sum of Exactly Three Non-Adjacent ElementsOA · Seen Jul 2025
  • Maximum Word Count in a SentenceOA · Seen Jul 2025
  • Minimum Digit Swaps for the Smallest DifferenceOA · Seen Jul 2025
  • Smallest String After at Most One DeletionOA · Seen Jul 2025
  • Delete One Digit 5 to Maximize the NumberOA · Seen Feb 2025
  • Three-Part Partition with Minimum Largest RangeOA · Seen Feb 2025
  • Price Equity Options and ForwardsOA · Seen Dec 2024
  • Maximum Sum of Non-Adjacent ElementsOA · Seen Sep 2024
  • Return the Sentence with the Most WordsOA · Seen Sep 2024

Similar questions at other companies

  • Rearrange String by Alternating EndsHudson River Trading · OAHudson River Trading interview questions
  • Alternate String EndsCapital One · OACapital One interview questions
  • Run-Length String CompressionSalesforce · OASalesforce interview questions
  • Minimum Changes for Palindromic BlocksCitadel · OA · PHONE SCREEN · ONSITE INTERVIEWCitadel interview questions
  • Count Binary SubstringsMicrosoft · OAMicrosoft interview questions
  • Check a Repeated String as a SubsequenceQuince · OAQuince interview questions
  • Reverse String In PlaceThe Walt Disney Company · OA · PHONE SCREENThe Walt Disney Company interview questions
  • Lost MessagesSuperhuman · OASuperhuman interview questions
  • Reverse a StringFlexTrade · OAFlexTrade interview questions
  • Missing WordsVanguard · OAVanguard interview questions

Interview reports that mention this question

  • LSEG Graduate Technology OA and Interviews: 7 Experiences
All LSEG interview questionsSee LSEG hiring insights
Saved
class Solution {
    public boolean canTransformOnce(String s, String t) {
        // write your code here
    }
}
Checking account…