Given a string, choose a lexicographically largest result under the problem’s allowed box-based selection rule.
Problem
You are given a string s. Think of the string as being placed in a box, and you must build a new string by selecting characters according to the rule described in the problem.
Your task is to return the lexicographically largest string that can be formed from the available characters under that rule.
In lexicographic order, a string is larger if at the first position where two strings differ, it has a larger character.
Goal
Construct the largest possible string according to the allowed operations and return it.
Input Format
- A single string
s. - The exact selection rule is implied by the platform problem statement; treat the string as the only input for solving the reconstruction task.
Output Format
- Return one string: the lexicographically largest string obtainable under the rule.
Constraints
1 <= |s|.- The solution should be efficient for typical interview-sized inputs.
- Characters are compared using standard lexicographic order.
Example 1
Input
s = "bac"
Output
"c"
Explanation
Under a rule that allows selecting from the available box content, the lexicographically largest obtainable single-character result is c.
Example 2
Input
s = "zabc"
Output
"z"
Explanation
The largest character available dominates the result when the rule permits choosing one best character from the box.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.