Company: UKG_15sep
Difficulty: medium
Find the Sequence Problem Description 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 k th turn: The player places the number i at the center of the current line segment. If direction[i] is '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 numbers on the line segment, starting from the left. Examples Example 1: Input: direction = "LRLLLL" There are n = 6 characters in the initial length of the line segment. The segment length is 2^6 = 64 in the range [0, 64] . The game proceeds as follows: Center Segment | Number | Direction | Remaining Segment ---------------|--------|-----------|------------------ [0, 64] | | | [0, 64] 32 | 1 | L | [0, 32] 16 | 2 | R | [16, 32] 24 |