As reported: Amazon SDE-1 fresher loop (India, February 2025), round 2 — a string question: strings
SandTof equal length made ofL,Rand-, where anLpiece moves left, anRpiece moves right and-is empty; check whetherScan be transformed intoTwithoutLandRpieces crossing. Count uni-valued subtrees and one Leadership Principle question followed.
This is LeetCode 2337 — Move Pieces to Obtain a String.
Strings start and target have the same length n and contain only 'L', 'R' and '_' (a blank). A piece 'L' can move one step left into a blank, a piece 'R' one step right into a blank, any number of times; pieces never jump over each other. Return true if start can be turned into target.
Example 1
start = "_L__R__R_", target = "L______RR"
Output: true
Example 2
start = "R_L_", target = "__LR"
Output: false
Constraints: 1 ≤ n ≤ 10⁵; both strings contain only 'L', 'R' and '_'.
Code runner format: LeetCode's test-case format — start and target as JSON strings, one per line. Implement canChange(start, target); the harness prints true or false.