PYTHON SOLUTION || EASY || EXPLAINED || DP || WELL WRITTTEN CODE||
Try putting Value at the position keeping in mind that the current value should be increasing or decreasing \nTo check this check s[pos - 1] \nNow since we cann
Try putting Value at the position keeping in mind that the current value should be increasing or decreasing \nTo check this check s[pos - 1] \nNow since we cannot repeat any digit we should use a dictionary to keep in check what value we used so far .\n\nOnce you find the no. of answer having index  = i and last item = x , put it on dp\n\n\n\n\n\n```\nclass Solution:\n    def recursion(self,idx,s,prev,limit,val,used):\n        if idx == limit + 1:\n            return 1\n        if (idx,prev) in self.dp:return self.dp[(idx,prev)]\n        start = 0 if s[idx-1] == \'D\' else prev + 1\n        end = prev -1 if s[idx-1] == \'D\' else limit\n        ans = 0\n        for i in range(start,end+1):\n            if i in used and used[i]==True:continue\n            used[i] = True\n            ans+=self.recursion(idx+1,s,i,limit,val+str(i),used)\n            used[i] = False\n        self.dp[(idx,prev)]=ans\n        return ans\n    def numPermsDISequence(self, s: str) -> int:\n        limit = len(s)\n        ans = 0\n        self.dp = {}\n        for i in range(limit+1):\n            ans+= self.recursion(1,s,i,limit,str(i),{i:True})\n        return ans%1000000007\n```
['Dynamic Programming', 'Recursion', 'Memoization', 'Python', 'Python3']