Scala solution
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: O(n^2)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(n^2)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nobject Solution {\n    def numPermsDISequence(s: String): Int = {\n      val n = s.length\n      val dp = Array.ofDim[Int](n+2, 2)\n      val mod = 1000000007\n      dp(1)(0) = 1\n      for (i <- 1 to n) \n        if (s(i-1) == \'I\') for (j <- 0 to i) dp(j+1)(i%2) = (dp(j)((i+1)%2) + dp(j)(i%2)) % mod\n        else for (j <- 0 to i) dp(j+1)(i%2) = ((dp(i)((i+1)%2) + mod - dp(j)((i+1)%2)) % mod + dp(j)(i%2)) % mod\n      dp(n+1)(n%2)\n    }\n}\n```
['Scala']