FastPrepModify the String
Problems/Modify the String

Modify the String

Yahoo logoYahoo● MediumOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Given a string input_str of length n, choose any character that occurs at least twice and delete any one occurrence. Repeat this until all remaining characters are distinct. The characters that are left keep their original order. Return the lexicographically maximum string that can be formed this way.

Function

getString(input_str: String) → String

Complete the function getString in the editor below.

getString has the following parameters:

  • string input_str: a string of length n

Returns string: the result of the operations, as described

Examples

Example 1

input_str = "aabcb"return = "acb"

The length of the string, n = 5. Some of the strings that can be formed are:

  • "acb" - delete the first occurrences of 'a' and 'b'
  • "abc" - delete the first occurrence of 'a' and the second occurrence of 'b'

It can be proven that the lexicographically maximum string that can be obtained is "acb".

Constraints

  • input_str contains only lowercase English letters
  • 1 ≤ n ≤ 10^5

More Yahoo interview questions

  • Logistic Regression with Gradient DescentPHONE SCREEN · Seen Nov 2026
  • Rank Unseen Items by Embedding SimilarityPHONE SCREEN · Seen Oct 2026
  • Count Binary SubstringsOA · Seen Mar 2025

Similar questions at other companies

  • Substring RemovalJP Morgan Chase · OAJP Morgan Chase interview questions
  • Lexicographically Minimum Stack EncryptionRippling · OARippling interview questions
  • Shortest String After Erasing Equal PairsMarshall Wace · OAMarshall Wace interview questions
  • Minimum Insertions to Balance a Parentheses StringIBM · OAIBM interview questions
  • Largest SubsequencesCashfree Payments · OA
  • Remove K Digits for the Smallest NumberNutanix · OANutanix interview questions
  • Good Binary StringsBNP Paribas · OA
  • Remove K DigitsProcol · PHONE SCREEN
  • Remove K DigitsThe D.E. Shaw Group · ONSITE INTERVIEWThe D.E. Shaw Group interview questions
  • Remove K DigitsAmazon · ONSITE INTERVIEW

Yahoo interview experiences

  • Yahoo Mail Senior MLE Interview Experience: 1 Experience
All Yahoo interview questionsSee Yahoo hiring insights
Saved
class Solution {
    public String getString(String input_str) {
      // write your code here
    }

}
Checking account…