1849. Splitting a String Into Descending Consecutive Values Medium

@problem@discussion
#String#Backtracking



1/**
2 * [1849] Splitting a String Into Descending Consecutive Values
3 *
4 * You are given a string s that consists of only digits.
5 * Check if we can split s into two or more non-empty substrings such that the numerical values of the substrings are in descending order and the difference between numerical values of every two adjacent substrings is equal to 1.
6 * 
7 * 	For example, the string s = "0090089" can be split into ["0090", "089"] with numerical values [90,89]. The values are in descending order and adjacent values differ by 1, so this way is valid.
8 * 	Another example, the string s = "001" can be split into ["0", "01"], ["00", "1"], or ["0", "0", "1"]. However all the ways are invalid because they have numerical values [0,1], [0,1], and [0,0,1] respectively, all of which are not in descending order.
9 * 
10 * Return true if it is possible to split s​​​​​​ as described above, or false otherwise.
11 * A substring is a contiguous sequence of characters in a string.
12 *  
13 * Example 1:
14 * 
15 * Input: s = "1234"
16 * Output: false
17 * Explanation: There is no valid way to split s.
18 * 
19 * Example 2:
20 * 
21 * Input: s = "050043"
22 * Output: true
23 * Explanation: s can be split into ["05", "004", "3"] with numerical values [5,4,3].
24 * The values are in descending order with adjacent values differing by 1.
25 * 
26 * Example 3:
27 * 
28 * Input: s = "9080701"
29 * Output: false
30 * Explanation: There is no valid way to split s.
31 * 
32 *  
33 * Constraints:
34 * 
35 * 	1 <= s.length <= 20
36 * 	s only consists of digits.
37 * 
38 */
39pub struct Solution {}
40
41// problem: https://leetcode.com/problems/splitting-a-string-into-descending-consecutive-values/
42// discuss: https://leetcode.com/problems/splitting-a-string-into-descending-consecutive-values/discuss/?currentPage=1&orderBy=most_votes&query=
43
44// submission codes start here
45
46impl Solution {
47    pub fn split_string(s: String) -> bool {
48        false
49    }
50}
51
52// submission codes end
53
54#[cfg(test)]
55mod tests {
56    use super::*;
57
58    #[test]
59    fn test_1849() {
60    }
61}
62


Back
© 2025 bowen.ge All Rights Reserved.