Class Solution
java.lang.Object
g2401_2500.s2434_using_a_robot_to_print_the_lexicographically_smallest_string.Solution
2434 - Using a Robot to Print the Lexicographically Smallest String.<p>Medium</p>
<p>You are given a string <code>s</code> and a robot that currently holds an empty string <code>t</code>. Apply one of the following operations until <code>s</code> and <code>t</code> <strong>are both empty</strong>:</p>
<ul>
<li>Remove the <strong>first</strong> character of a string <code>s</code> and give it to the robot. The robot will append this character to the string <code>t</code>.</li>
<li>Remove the <strong>last</strong> character of a string <code>t</code> and give it to the robot. The robot will write this character on paper.</li>
</ul>
<p>Return <em>the lexicographically smallest string that can be written on the paper.</em></p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> s = “zza”</p>
<p><strong>Output:</strong> “azz”</p>
<p><strong>Explanation:</strong> Let p denote the written string.</p>
<p>Initially p=““, s=“zza”, t=””.</p>
<p>Perform first operation three times p=““, s=””, t=“zza”.</p>
<p>Perform second operation three times p=“azz”, s=““, t=””.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> s = “bac”</p>
<p><strong>Output:</strong> “abc”</p>
<p><strong>Explanation:</strong> Let p denote the written string.</p>
<p>Perform first operation twice p="", s=“c”, t=“ba”.</p>
<p>Perform second operation twice p=“ab”, s=“c”, t="".</p>
<p>Perform first operation p=“ab”, s="", t=“c”.</p>
<p>Perform second operation p=“abc”, s=““, t=””.</p>
<p><strong>Example 3:</strong></p>
<p><strong>Input:</strong> s = “bdda”</p>
<p><strong>Output:</strong> “addb”</p>
<p><strong>Explanation:</strong> Let p denote the written string.</p>
<p>Initially p=““, s=“bdda”, t=””.</p>
<p>Perform first operation four times p=““, s=””, t=“bdda”.</p>
<p>Perform second operation four times p=“addb”, s=““, t=””.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= s.length <= 10<sup>5</sup></code></li>
<li><code>s</code> consists of only English lowercase letters.</li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
robotWithString
-