2337. Move Pieces to Obtain a String Medium
1/**
2 * [2337] Move Pieces to Obtain a String
3 *
4 * You are given two strings start and target, both of length n. Each string consists only of the characters 'L', 'R', and '_' where:
5 *
6 * The characters 'L' and 'R' represent pieces, where a piece 'L' can move to the left only if there is a blank space directly to its left, and a piece 'R' can move to the right only if there is a blank space directly to its right.
7 * The character '_' represents a blank space that can be occupied by any of the 'L' or 'R' pieces.
8 *
9 * Return true if it is possible to obtain the string target by moving the pieces of the string start any number of times. Otherwise, return false.
10 *
11 * Example 1:
12 *
13 * Input: start = "_L__R__R_", target = "L______RR"
14 * Output: true
15 * Explanation: We can obtain the string target from start by doing the following moves:
16 * - Move the first piece one step to the left, start becomes equal to "L___R__R_".
17 * - Move the last piece one step to the right, start becomes equal to "L___R___R".
18 * - Move the second piece three steps to the right, start becomes equal to "L______RR".
19 * Since it is possible to get the string target from start, we return true.
20 *
21 * Example 2:
22 *
23 * Input: start = "R_L_", target = "__LR"
24 * Output: false
25 * Explanation: The 'R' piece in the string start can move one step to the right to obtain "_RL_".
26 * After that, no pieces can move anymore, so it is impossible to obtain the string target from start.
27 *
28 * Example 3:
29 *
30 * Input: start = "_R", target = "R_"
31 * Output: false
32 * Explanation: The piece in the string start can move only to the right, so it is impossible to obtain the string target from start.
33 *
34 * Constraints:
35 *
36 * n == start.length == target.length
37 * 1 <= n <= 10^5
38 * start and target consist of the characters 'L', 'R', and '_'.
39 *
40 */
41pub struct Solution {}
42
43// problem: https://leetcode.com/problems/move-pieces-to-obtain-a-string/
44// discuss: https://leetcode.com/problems/move-pieces-to-obtain-a-string/discuss/?currentPage=1&orderBy=most_votes&query=
45
46// submission codes start here
47
48impl Solution {
49 pub fn can_change(start: String, target: String) -> bool {
50 false
51 }
52}
53
54// submission codes end
55
56#[cfg(test)]
57mod tests {
58 use super::*;
59
60 #[test]
61 fn test_2337() {
62 }
63}
64
Back
© 2025 bowen.ge All Rights Reserved.