Class Solution
-
- All Implemented Interfaces:
public final class Solution2434 - Using a Robot to Print the Lexicographically Smallest String\.
Medium
You are given a string
sand a robot that currently holds an empty stringt. Apply one of the following operations untilsandtare both empty:Remove the first character of a string
sand give it to the robot. The robot will append this character to the stringt.Remove the last character of a string
tand give it to the robot. The robot will write this character on paper.
Return the lexicographically smallest string that can be written on the paper.
Example 1:
Input: s = "zza"
Output: "azz"
Explanation: Let p denote the written string.
Initially p="", s="zza", t="".
Perform first operation three times p="", s="", t="zza".
Perform second operation three times p="azz", s="", t="".
Example 2:
Input: s = "bac"
Output: "abc"
Explanation: Let p denote the written string.
Perform first operation twice p="", s="c", t="ba".
Perform second operation twice p="ab", s="c", t="".
Perform first operation p="ab", s="", t="c".
Perform second operation p="abc", s="", t="".
Example 3:
Input: s = "bdda"
Output: "addb"
Explanation: Let p denote the written string.
Initially p="", s="bdda", t="".
Perform first operation four times p="", s="", t="bdda".
Perform second operation four times p="addb", s="", t="".
Constraints:
<code>1 <= s.length <= 10<sup>5</sup></code>
sconsists of only English lowercase letters.
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
Modifier and Type Method Description final StringrobotWithString(String s)-
-
Method Detail
-
robotWithString
final String robotWithString(String s)
-
-
-
-