3519. Count Numbers with Non-Decreasing Digits Hard
1/**
2 * [3519] Count Numbers with Non-Decreasing Digits
3 *
4 * You are given two integers, l and r, represented as strings, and an integer b. Return the count of integers in the inclusive range [l, r] whose digits are in non-decreasing order when represented in base b.
5 * An integer is considered to have non-decreasing digits if, when read from left to right (from the most significant digit to the least significant digit), each digit is greater than or equal to the previous one.
6 * Since the answer may be too large, return it modulo 10^9 + 7.
7 *
8 * <strong class="example">Example 1:
9 * <div class="example-block">
10 * Input: <span class="example-io">l = "23", r = "28", b = 8</span>
11 * Output: <span class="example-io">3</span>
12 * Explanation:
13 *
14 * The numbers from 23 to 28 in base 8 are: 27, 30, 31, 32, 33, and 34.
15 * Out of these, 27, 33, and 34 have non-decreasing digits. Hence, the output is 3.
16 * </div>
17 * <strong class="example">Example 2:
18 * <div class="example-block">
19 * Input: <span class="example-io">l = "2", r = "7", b = 2</span>
20 * Output: <span class="example-io">2</span>
21 * Explanation:
22 *
23 * The numbers from 2 to 7 in base 2 are: 10, 11, 100, 101, 110, and 111.
24 * Out of these, 11 and 111 have non-decreasing digits. Hence, the output is 2.
25 * </div>
26 *
27 * Constraints:
28 *
29 * <font face="monospace">1 <= l.length <= r.length <= 100</font>
30 * 2 <= b <= 10
31 * l and r consist only of digits.
32 * The value represented by l is less than or equal to the value represented by r.
33 * l and r do not contain leading zeros.
34 *
35 */
36pub struct Solution {}
37
38// problem: https://leetcode.com/problems/count-numbers-with-non-decreasing-digits/
39// discuss: https://leetcode.com/problems/count-numbers-with-non-decreasing-digits/discuss/?currentPage=1&orderBy=most_votes&query=
40
41// submission codes start here
42
43impl Solution {
44 pub fn count_numbers(l: String, r: String, b: i32) -> i32 {
45 0
46 }
47}
48
49// submission codes end
50
51#[cfg(test)]
52mod tests {
53 use super::*;
54
55 #[test]
56 fn test_3519() {
57 }
58}
59Back
© 2026 bowen.ge All Rights Reserved.