3784. Minimum Deletion Cost to Make All Characters Equal Medium
1/**
2 * [3784] Minimum Deletion Cost to Make All Characters Equal
3 *
4 * You are given a string s of length n and an integer array cost of the same length, where cost[i] is the cost to delete the i^th character of s.
5 * You may delete any number of characters from s (possibly none), such that the resulting string is non-empty and consists of equal characters.
6 * Return an integer denoting the minimum total deletion cost required.
7 *
8 * <strong class="example">Example 1:
9 * <div class="example-block">
10 * Input: <span class="example-io">s = "aabaac", cost = [1,2,3,4,1,10]</span>
11 * Output: <span class="example-io">11</span>
12 * Explanation:
13 * Deleting the characters at indices 0, 1, 2, 3, 4 results in the string "c", which consists of equal characters, and the total cost is cost[0] + cost[1] + cost[2] + cost[3] + cost[4] = 1 + 2 + 3 + 4 + 1 = 11.
14 * </div>
15 * <strong class="example">Example 2:
16 * <div class="example-block">
17 * Input: <span class="example-io">s = "abc", cost = [10,5,8]</span>
18 * Output: <span class="example-io">13</span>
19 * Explanation:
20 * Deleting the characters at indices 1 and 2 results in the string "a", which consists of equal characters, and the total cost is cost[1] + cost[2] = 5 + 8 = 13.
21 * </div>
22 * <strong class="example">Example 3:
23 * <div class="example-block">
24 * Input: <span class="example-io">s = "zzzzz", cost = [67,67,67,67,67]</span>
25 * Output: <span class="example-io">0</span>
26 * Explanation:
27 * All characters in s are equal, so the deletion cost is 0.
28 * </div>
29 *
30 * Constraints:
31 *
32 * n == s.length == cost.length
33 * 1 <= n <= 10^5
34 * 1 <= cost[i] <= 10^9
35 * s consists of lowercase English letters.
36 *
37 */
38pub struct Solution {}
39
40// problem: https://leetcode.com/problems/minimum-deletion-cost-to-make-all-characters-equal/
41// discuss: https://leetcode.com/problems/minimum-deletion-cost-to-make-all-characters-equal/discuss/?currentPage=1&orderBy=most_votes&query=
42
43// submission codes start here
44
45impl Solution {
46 pub fn min_cost(s: String, cost: Vec<i32>) -> i64 {
47
48 }
49}
50
51// submission codes end
52
53#[cfg(test)]
54mod tests {
55 use super::*;
56
57 #[test]
58 fn test_3784() {
59 }
60}
61Back
© 2026 bowen.ge All Rights Reserved.