2434. Using a Robot to Print the Lexicographically Smallest String Medium

@problem@discussion
#Hash Table#String#Stack#Greedy



1/**
2 * [2434] Using a Robot to Print the Lexicographically Smallest String
3 *
4 * You are given a string s and a robot that currently holds an empty string t. Apply one of the following operations until s and t are both empty:
5 * 
6 * 	Remove the first character of a string s and give it to the robot. The robot will append this character to the string t.
7 * 	Remove the last character of a string t and give it to the robot. The robot will write this character on paper.
8 * 
9 * Return the lexicographically smallest string that can be written on the paper.
10 *  
11 * <strong class="example">Example 1:
12 * 
13 * Input: s = "zza"
14 * Output: "azz"
15 * Explanation: Let p denote the written string.
16 * Initially p="", s="zza", t="".
17 * Perform first operation three times p="", s="", t="zza".
18 * Perform second operation three times p="azz", s="", t="".
19 * 
20 * <strong class="example">Example 2:
21 * 
22 * Input: s = "bac"
23 * Output: "abc"
24 * Explanation: Let p denote the written string.
25 * Perform first operation twice p="", s="c", t="ba". 
26 * Perform second operation twice p="ab", s="c", t="". 
27 * Perform first operation p="ab", s="", t="c". 
28 * Perform second operation p="abc", s="", t="".
29 * 
30 * <strong class="example">Example 3:
31 * 
32 * Input: s = "bdda"
33 * Output: "addb"
34 * Explanation: Let p denote the written string.
35 * Initially p="", s="bdda", t="".
36 * Perform first operation four times p="", s="", t="bdda".
37 * Perform second operation four times p="addb", s="", t="".
38 * 
39 *  
40 * Constraints:
41 * 
42 * 	1 <= s.length <= 10^5
43 * 	s consists of only English lowercase letters.
44 * 
45 */
46pub struct Solution {}
47
48// problem: https://leetcode.com/problems/using-a-robot-to-print-the-lexicographically-smallest-string/
49// discuss: https://leetcode.com/problems/using-a-robot-to-print-the-lexicographically-smallest-string/discuss/?currentPage=1&orderBy=most_votes&query=
50
51// submission codes start here
52
53impl Solution {
54    pub fn robot_with_string(s: String) -> String {
55        String::new()
56    }
57}
58
59// submission codes end
60
61#[cfg(test)]
62mod tests {
63    use super::*;
64
65    #[test]
66    fn test_2434() {
67    }
68}
69


Back
© 2025 bowen.ge All Rights Reserved.