1505. Minimum Possible Integer After at Most K Adjacent Swaps On Digits Hard

@problem@discussion
#String#Greedy#Binary Indexed Tree#Segment Tree



1/**
2 * [1505] Minimum Possible Integer After at Most K Adjacent Swaps On Digits
3 *
4 * You are given a string num representing the digits of a very large integer and an integer k. You are allowed to swap any two adjacent digits of the integer at most k times.
5 * Return the minimum integer you can obtain also as a string.
6 *  
7 * Example 1:
8 * <img alt="" src="https://assets.leetcode.com/uploads/2020/06/17/q4_1.jpg" style="width: 500px; height: 40px;" />
9 * Input: num = "4321", k = 4
10 * Output: "1342"
11 * Explanation: The steps to obtain the minimum integer from 4321 with 4 adjacent swaps are shown.
12 * 
13 * Example 2:
14 * 
15 * Input: num = "100", k = 1
16 * Output: "010"
17 * Explanation: It's ok for the output to have leading zeros, but the input is guaranteed not to have any leading zeros.
18 * 
19 * Example 3:
20 * 
21 * Input: num = "36789", k = 1000
22 * Output: "36789"
23 * Explanation: We can keep the number without any swaps.
24 * 
25 *  
26 * Constraints:
27 * 
28 * 	1 <= num.length <= 3 * 10^4
29 * 	num consists of only digits and does not contain leading zeros.
30 * 	1 <= k <= 10^9
31 * 
32 */
33pub struct Solution {}
34
35// problem: https://leetcode.com/problems/minimum-possible-integer-after-at-most-k-adjacent-swaps-on-digits/
36// discuss: https://leetcode.com/problems/minimum-possible-integer-after-at-most-k-adjacent-swaps-on-digits/discuss/?currentPage=1&orderBy=most_votes&query=
37
38// submission codes start here
39
40impl Solution {
41    pub fn min_integer(num: String, k: i32) -> String {
42        String::new()
43    }
44}
45
46// submission codes end
47
48#[cfg(test)]
49mod tests {
50    use super::*;
51
52    #[test]
53    fn test_1505() {
54    }
55}
56


Back
© 2025 bowen.ge All Rights Reserved.