Here is the solution without reverse:

public int[] findPermutation(String s) { final int[] res = IntStream.rangeClosed(1, s.length() + 1).toArray(); for (int i = 0, len = s.length(); i < len;) { int j = i; while (j < len && s.charAt(j) == 'D') { j++; } for (int k = j - i; k >= 0; k--, j--) { res[i++] = j + 1; } } return res; }Find Permutation