Solution Valid Permutations for DI Sequence
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n\n    /**\n     * @param String $s\n     * @return Integer\n     */\n    function numPermsDISequence($s) {\n        $mod = 1000000007;\n        $n = strlen($s);\n        \n        $dp = array_fill(0, $n + 1, 1);\n        \n        for ($i = 0; $i < $n; $i++) {\n            $next = array_fill(0, $n + 1, 0);\n            if ($s[$i] == \'I\') {\n                $sum = 0;\n                for ($j = 0; $j < $n - $i; $j++) {\n                    $sum = ($sum + $dp[$j]) % $mod;\n                    $next[$j] = $sum;\n                }\n            } else {\n                $sum = 0;\n                for ($j = $n - $i - 1; $j >= 0; $j--) {\n                    $sum = ($sum + $dp[$j + 1]) % $mod;\n                    $next[$j] = $sum;\n                }\n            }\n            $dp = $next;\n        }\n        \n        return $dp[0];\n    }\n}\n\n```
['PHP']