👍Runtime 598 ms  Beats 100.00% of users with Scala
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 
# 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\n        for (i <- 1 to n) {\n            if (s.charAt(i - 1) == \'I\') {\n                for (j <- 0 to i) dp(j + 1)(i & 1) = (dp(j)((i + 1) & 1) + dp(j)(i & 1)) % mod\n            } else {\n                for (j <- 0 to i) dp(j + 1)(i & 1) = ((dp(i)((i + 1) & 1) + mod - dp(j)((i + 1) & 1)) % mod + dp(j)(i & 1)) % mod\n            }\n        }\n\n        dp(n + 1)(n & 1)\n    }\n}\n```
['Scala']