Skip to content

2337. Move Pieces to Obtain a String #916

Answered by mah-shamim
mah-shamim asked this question in Q&A
Discussion options

You must be logged in to vote

We need to check if we can transform the string start into the string target by moving pieces ('L' and 'R') as per the given rules. The main constraints to consider are:

  • 'L' can only move left (and cannot cross other 'L' or 'R' pieces).
  • 'R' can only move right (and cannot cross other 'L' or 'R' pieces).
  • We can use any blank spaces ('_') to move pieces around.

Plan:

  1. Length Check: First, check if both strings have the same length. If they don't, return false immediately.

  2. Character Frequency Check: The number of 'L's, 'R's, and '_' in the start string must match the respective counts in the target string because the pieces cannot be duplicated or destroyed, only moved.

  3. Piece Matching…

Replies: 1 comment 2 replies

Comment options

mah-shamim
Dec 5, 2024
Maintainer Author

You must be logged in to vote
2 replies
@basharul-siddike
Comment options

@mah-shamim
Comment options

mah-shamim Dec 5, 2024
Maintainer Author

Answer selected by basharul-siddike
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested medium Difficulty
2 participants