Greater than less than greater than something fishy Given a length N string of less-than and greater-than signs (&lt;, &gt;), 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
&lt;&lt;&gt;&lt;&gt;&lt;&lt;

has 7 characters so all the numbers from 0 to 7 inclusive must be inserted. A valid output is
2&lt;3&lt;4&gt;1&lt;5&gt;0&lt;6&lt;7

because all the inequalities taken one at a time
2&lt;3
3&lt;4
4&gt;1
1&lt;5
5&gt;0
0&lt;6
6&lt;7

are true.
If desired, the output may have spaces surrounding the signs, e.g. 2 &lt; 3 &lt; 4 &gt; 1 &lt; 5 &gt; 0 &lt; 6 &lt; 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

&lt;
0&lt;1

&gt;
1&gt;0

&lt;&lt;
0&lt;1&lt;2

&lt;&gt;
1&lt;2&gt;0

&gt;&lt;
1&gt;0&lt;2
2&gt;0&lt;1

&gt;&gt;
2&gt;1&gt;0

&lt;&lt;&lt;
0&lt;1&lt;2&lt;3

&gt;&lt;&gt;
1&gt;0&lt;3&gt;2

&gt;&gt;&lt;
3&gt;2&gt;0&lt;1
3&gt;1&gt;0&lt;2
2&gt;1&gt;0&lt;3

&gt;&gt;&gt;
3&gt;2&gt;1&gt;0

&gt;&gt;&gt;&lt;&lt;&lt;
3&gt;2&gt;1&gt;0&lt;4&lt;5&lt;6
6&gt;3&gt;1&gt;0&lt;2&lt;4&lt;5
4&gt;2&gt;1&gt;0&lt;3&lt;5&lt;6
4&gt;3&gt;1&gt;0&lt;2&lt;5&lt;6

&lt;&lt;&gt;&lt;&gt;&lt;&lt;
2&lt;3&lt;4&gt;1&lt;5&gt;0&lt;6&lt;7

&gt;&gt;&lt;&gt;&lt;&gt;&gt;
7&gt;6&gt;0&lt;5&gt;1&lt;4&gt;3&gt;2

&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;
0&lt;1&lt;2&lt;3&lt;4&lt;5&lt;6&lt;7&lt;8&lt;9&lt;10&lt;11&lt;12&lt;13&lt;14

&gt;&gt;&lt;&lt;&lt;&lt;&gt;&lt;&gt;&gt;&lt;&gt;&lt;&lt;
6&gt;5&gt;4&lt;7&lt;8&lt;9&lt;10&gt;3&lt;11&gt;2&gt;1&lt;12&gt;0&lt;13&lt;14
14&gt;5&gt;4&lt;7&lt;8&lt;9&lt;10&gt;3&lt;11&gt;2&gt;1&lt;12&gt;0&lt;13&lt;6
Retina, 20 bytes

Byte count assumes ISO 8859-1 encoding.


$.'
S`>
%O#`\d+
¶
>

Try it online! (The first line enables a linefeed-separated test-suite.)

Explanation

A simple way to find a valid permutation is to start by inserting the numbers from 0 to N in order, and then to reverse the numbers surrounding each substring of &gt;s. Take &lt;&gt;&lt;&lt;&gt;&gt;&gt;&lt;&lt; as an example:

0&lt;1&gt;2&lt;3&lt;4&gt;5&gt;6&gt;7&lt;8&lt;9
  ---   -------      these sections are wrong, so we reverse them
0&lt;2&gt;1&lt;3&lt;7&gt;6&gt;5&gt;4&lt;8&lt;9


Both of those tasks are fairly simple in Retina, even though all we can really work with are strings. We can save an additional byte by inserting the numbers from N down to 0 and reversing the sections surrounding &lt; instead, but the principle is the same.

Stage 1: Substitution


$.'

We start by inserting the length of $' (the suffix, i.e. everything after the match) into every possible position in the input. This inserts the numbers from N down to 0.

Stage 2: Split

S`&gt;


We split the input around &gt; into separate lines, so each line is either an individual number or a list of numbers joined with &lt;.

Stage 3: Sort

%O#`\d+


Within each line (%) we sort (O) the numbers (\d#) by their numerical value (#). Since we inserted the number in reverse numerical order, this reverses them.

Stage 4: Substitution

¶
&gt;


We turn the linefeeds into &gt; again to join everything back into a single line. That's it.

As a side note, I've been meaning to add a way to apply % to other delimiters than linefeeds. Had I already done that, this submission would have been 14 bytes, because then the last three stages would have been reduced to a single one:

%'&gt;O#`\d+