Given a length N string of less-than and greater-than signs (<
, >
), insert the integers 0 through N at the start and end and in between each pair of signs such that all the inequalities are satisfied. Output the resulting string. If there are multiple valid outputs, output any one (and just one) of them.
For example
<<><><<
has 7 characters so all the numbers from 0 to 7 inclusive must be inserted. A valid output is
2<3<4>1<5>0<6<7
because all the inequalities taken one at a time
2<3
3<4
4>1
1<5
5>0
0<6
6<7
are true.
If desired, the output may have spaces surrounding the signs, e.g. 2 < 3 < 4 > 1 < 5 > 0 < 6 < 7
.
The shortest code in bytes wins.
Test Cases
The first line after an empty line is the input and the next line(s) are each valid output examples.
[empty string]
0
<
0<1
>
1>0
<<
0<1<2
<>
1<2>0
><
1>0<2
2>0<1
>>
2>1>0
<<<
0<1<2<3
><>
1>0<3>2
>><
3>2>0<1
3>1>0<2
2>1>0<3
>>>
3>2>1>0
>>><<<
3>2>1>0<4<5<6
6>3>1>0<2<4<5
4>2>1>0<3<5<6
4>3>1>0<2<5<6
<<><><<
2<3<4>1<5>0<6<7
>><><>>
7>6>0<5>1<4>3>2
<<<<<<<<<<<<<<
0<1<2<3<4<5<6<7<8<9<10<11<12<13<14
>><<<<><>><><<
6>5>4<7<8<9<10>3<11>2>1<12>0<13<14
14>5>4<7<8<9<10>3<11>2>1<12>0<13<6
<>
can also be0<2>1
as possible valid output. \$\endgroup\$