<p>In a string composed of <code>&#39;L&#39;</code>, <code>&#39;R&#39;</code>, and <code>&#39;X&#39;</code> characters, like <code>&quot;RXXLRXRXL&quot;</code>, a move consists of either replacing one occurrence of <code>&quot;XL&quot;</code> with <code>&quot;LX&quot;</code>, or replacing one occurrence of <code>&quot;RX&quot;</code> with <code>&quot;XR&quot;</code>. Given the starting string <code>start</code> and the ending string <code>end</code>, return <code>True</code> if and only if there exists a sequence of moves to transform <code>start</code> to <code>end</code>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> start = &quot;RXXLRXRXL&quot;, end = &quot;XRLXXRRLX&quot;
<strong>Output:</strong> true
<strong>Explanation:</strong> We can transform start to end following these steps:
RXXLRXRXL -&gt;
XRXLRXRXL -&gt;
XRLXRXRXL -&gt;
XRLXXRRXL -&gt;
XRLXXRRLX
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> start = &quot;X&quot;, end = &quot;L&quot;
<strong>Output:</strong> false
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= start.length&nbsp;&lt;= 10<sup>4</sup></code></li>
	<li><code>start.length == end.length</code></li>
	<li>Both <code>start</code> and <code>end</code> will only consist of characters in <code>&#39;L&#39;</code>, <code>&#39;R&#39;</code>, and&nbsp;<code>&#39;X&#39;</code>.</li>
</ul>


"""
"X"
 ^
"L"
 ^
 
startx = 0
endx = 0

"""

class Solution:
    def canTransform(self, start: str, end: str) -> bool:
        
        if len(start) != len(end):
            return False
        
        start_index = 0
        end_index = 0
        
        while start_index < len(start) and end_index < len(end):
            
            while start_index < len(start) and start[start_index] == 'X':
                start_index += 1
            while end_index < len(end) and end[end_index] == 'X':
                end_index += 1
                
            if start_index < len(start) and end_index < len(end) and start[start_index] != end[end_index]:
                return False
            
            start_index += 1
            end_index += 1

        while start_index < len(start) and start[start_index] == 'X':
            start_index += 1
        while end_index < len(end) and end[end_index] == 'X':
            end_index += 1
            
        return start_index == end_index

    def canTransform(self, start: str, end: str) -> bool:

        so , eo , sind, eind = [],[],[],[]
        for i in range(len(start)):
            if start[i] != 'X':
                so.append(start[i])
                sind.append(i)
            if end[i] != 'X':
                eo.append(end[i])
                eind.append(i)
        if so != eo:
            return False
        
        for j in range(len(so)):
            if so[j] == 'L' and eind[j]>sind[j]:
                return False
            if so[j] == 'R' and eind[j]<sind[j]:
                return False
        
        return True
        
17400