Company: UKG
Difficulty: medium
Find the Sequence In a game, there is a string, direction , of length n that consists of characters 'L' and 'R'. L denotes left, R denotes right, and there is a line segment of length 2 n that extends from [0, 2 n ), a player takes n turns. In the i th turn, the player places the number i at the center of the current line segment. If direction [ i ] = 'L', the player proceeds in the left direction, eliminating the right half of the current line segment, and vice versa for direction [ i ] = 'R'. Following this rule, find the final order of the numbers on the line segment, starting from the left. The first line contains a string, direction . An integer array that denotes the indices of characters in the string ordered by placement point. \(1 \le n \le 5 \times 10^5\) The string direction consists of 'L' or 'R' only. Examples Example 1 Input: LRLRRL Output: 2 4 5 6 3 1 Explanation: Given \(n=6\), the initial length of the line segment is \(2^6 = 64\), thus line segment is [0, 64]. The gam