Skip to content

Commit ad882a5

Browse files
committed
2193. Minimum Number of Moves to Make Palindrome: RETRY
1 parent c5a76c9 commit ad882a5

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed

src/solution/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1658,3 +1658,4 @@ mod s2188_minimum_time_to_finish_the_race;
16581658
mod s2190_most_frequent_number_following_key_in_an_array;
16591659
mod s2191_sort_the_jumbled_numbers;
16601660
mod s2192_all_ancestors_of_a_node_in_a_directed_acyclic_graph;
1661+
mod s2193_minimum_number_of_moves_to_make_palindrome;
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/**
2+
* [2193] Minimum Number of Moves to Make Palindrome
3+
*
4+
* You are given a string s consisting only of lowercase English letters.
5+
* In one move, you can select any two adjacent characters of s and swap them.
6+
* Return the minimum number of moves needed to make s a palindrome.
7+
* Note that the input will be generated such that s can always be converted to a palindrome.
8+
*
9+
* Example 1:
10+
*
11+
* Input: s = "aabb"
12+
* Output: 2
13+
* Explanation:
14+
* We can obtain two palindromes from s, "abba" and "baab".
15+
* - We can obtain "abba" from s in 2 moves: "a<u>ab</u>b" -> "ab<u>ab</u>" -> "abba".
16+
* - We can obtain "baab" from s in 2 moves: "a<u>ab</u>b" -> "<u>ab</u>ab" -> "baab".
17+
* Thus, the minimum number of moves needed to make s a palindrome is 2.
18+
*
19+
* Example 2:
20+
*
21+
* Input: s = "letelt"
22+
* Output: 2
23+
* Explanation:
24+
* One of the palindromes we can obtain from s in 2 moves is "lettel".
25+
* One of the ways we can obtain it is "lete<u>lt</u>" -> "let<u>et</u>l" -> "lettel".
26+
* Other palindromes such as "tleelt" can also be obtained in 2 moves.
27+
* It can be shown that it is not possible to obtain a palindrome in less than 2 moves.
28+
*
29+
*
30+
* Constraints:
31+
*
32+
* 1 <= s.length <= 2000
33+
* s consists only of lowercase English letters.
34+
* s can be converted to a palindrome using a finite number of moves.
35+
*
36+
*/
37+
pub struct Solution {}
38+
39+
// problem: https://leetcode.com/problems/minimum-number-of-moves-to-make-palindrome/
40+
// discuss: https://leetcode.com/problems/minimum-number-of-moves-to-make-palindrome/discuss/?currentPage=1&orderBy=most_votes&query=
41+
42+
// submission codes start here
43+
44+
impl Solution {
45+
pub fn min_moves_to_make_palindrome(s: String) -> i32 {
46+
0
47+
}
48+
}
49+
50+
// submission codes end
51+
52+
#[cfg(test)]
53+
mod tests {
54+
use super::*;
55+
56+
#[test]
57+
#[ignore]
58+
fn test_2193_example_1() {
59+
let s = "aabb".to_string();
60+
61+
let result = 2;
62+
63+
assert_eq!(Solution::min_moves_to_make_palindrome(s), result);
64+
}
65+
66+
#[test]
67+
#[ignore]
68+
fn test_2193_example_2() {
69+
let s = "letelt".to_string();
70+
71+
let result = 2;
72+
73+
assert_eq!(Solution::min_moves_to_make_palindrome(s), result);
74+
}
75+
}

0 commit comments

Comments
 (0)