1370. Increasing Decreasing String Easy
1/**
2 * [1370] Increasing Decreasing String
3 *
4 * You are given a string s. Reorder the string using the following algorithm:
5 * <ol>
6 * Pick the smallest character from s and append it to the result.
7 * Pick the smallest character from s which is greater than the last appended character to the result and append it.
8 * Repeat step 2 until you cannot pick more characters.
9 * Pick the largest character from s and append it to the result.
10 * Pick the largest character from s which is smaller than the last appended character to the result and append it.
11 * Repeat step 5 until you cannot pick more characters.
12 * Repeat the steps from 1 to 6 until you pick all characters from s.
13 * </ol>
14 * In each step, If the smallest or the largest character appears more than once you can choose any occurrence and append it to the result.
15 * Return the result string after sorting s with this algorithm.
16 *
17 * Example 1:
18 *
19 * Input: s = "aaaabbbbcccc"
20 * Output: "abccbaabccba"
21 * Explanation: After steps 1, 2 and 3 of the first iteration, result = "abc"
22 * After steps 4, 5 and 6 of the first iteration, result = "abccba"
23 * First iteration is done. Now s = "aabbcc" and we go back to step 1
24 * After steps 1, 2 and 3 of the second iteration, result = "abccbaabc"
25 * After steps 4, 5 and 6 of the second iteration, result = "abccbaabccba"
26 *
27 * Example 2:
28 *
29 * Input: s = "rat"
30 * Output: "art"
31 * Explanation: The word "rat" becomes "art" after re-ordering it with the mentioned algorithm.
32 *
33 *
34 * Constraints:
35 *
36 * 1 <= s.length <= 500
37 * s consists of only lowercase English letters.
38 *
39 */
40pub struct Solution {}
41
42// problem: https://leetcode.com/problems/increasing-decreasing-string/
43// discuss: https://leetcode.com/problems/increasing-decreasing-string/discuss/?currentPage=1&orderBy=most_votes&query=
44
45// submission codes start here
46
47impl Solution {
48 pub fn sort_string(s: String) -> String {
49 String::new()
50 }
51}
52
53// submission codes end
54
55#[cfg(test)]
56mod tests {
57 use super::*;
58
59 #[test]
60 fn test_1370() {
61 }
62}
63
Back
© 2025 bowen.ge All Rights Reserved.