Zepruv › Coding problems

DI String Match

Easy · Array, Two Pointers, String, Greedy

A permutation perm of n + 1 integers of all the integers in the range [0, n] can be represented as a string s of length n where:
Given a string s, reconstruct the permutation perm and return it. If there are multiple valid permutations perm, return any of them.

Example 1

Input: s = "IDID"
Output: [0,4,1,3,2]

Example 2

Input: s = "III"
Output: [0,1,2,3]

Example 3

Input: s = "DDI"
Output: [3,2,0,1]

Constraints

Starter code (python)

class Solution(object):
    def diStringMatch(self, s):
        """
        :type s: str
        :rtype: List[int]
        """
        

Related problems

Previous: Valid Mountain Array · Next: Delete Columns to Make Sorted · All problems

Zepruv is a technical interview practice platform. Read any problem for free; sign in to run your code, submit and keep your progress.