Skip to content

Practice Move Pieces to Obtain a String

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#2337
LeetCode Problem

Move Pieces to Obtain a String

Problem Statement

start and target use L, R, and blank _. An L piece may swap with a blank immediately to its left, and an R piece may swap with a blank immediately to its right. No other moves are allowed. Return whether repeated moves can transform start into target.

Source: Move Pieces to Obtain a String on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
start = "_L__R__R_", target = "L______RR"
Output
true

# Example 2

Input
start = "R_L_", target = "__LR"
Output
false

# Example 3

Input
start = "_R", target = "R_"
Output
false

Constraints

n == start.length == target.length
1 <= n <= 10^5
start and target consist of the characters 'L', 'R', and '_'.

Related LeetCode Problems

Practice more problems similar to Move Pieces to Obtain a String.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.