Tap here to switch tabs
Problem
Submissions

Problem: Move Pieces to Obtain a String

med
30 min
Try to solve the Move Pieces to Obtain a String problem.

Statement

You are given two strings start and target, both of length n. Each string consists exclusively of the characters 'L', 'R', and '_'. The characters 'L' and 'R' represent movable pieces, while '_' represents an empty space.

A piece can move according to the following rules:

  • A piece 'L' can only move to the left into an adjacent empty space '_'.

  • A piece 'R' can only move to the right into an adjacent empty space '_'.

Pieces cannot jump over or pass each other.

Return true if it is possible to obtain the string target from start through any number of valid moves. Otherwise, return false.

Constraints:

  • n == start.length == target.length

  • 1≤1 \leq n ≤105\leq 10^5

  • start and target consist of the characters 'L', 'R', and '_'.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Move Pieces to Obtain a String

med
30 min
Try to solve the Move Pieces to Obtain a String problem.

Statement

You are given two strings start and target, both of length n. Each string consists exclusively of the characters 'L', 'R', and '_'. The characters 'L' and 'R' represent movable pieces, while '_' represents an empty space.

A piece can move according to the following rules:

  • A piece 'L' can only move to the left into an adjacent empty space '_'.

  • A piece 'R' can only move to the right into an adjacent empty space '_'.

Pieces cannot jump over or pass each other.

Return true if it is possible to obtain the string target from start through any number of valid moves. Otherwise, return false.

Constraints:

  • n == start.length == target.length

  • 1≤1 \leq n ≤105\leq 10^5

  • start and target consist of the characters 'L', 'R', and '_'.