Use DP - Easy to Understand - ✅|| Java || 24 ms ||🔥|| Beats 100.00% ||🏆
Code\n\nclass Solution {\n    private static final int MOD = 1_000_000_007;\n\n    public int countOfPairs(int[] nums) {\n        int prefixZeros = 0;\n        
# Code\n```\nclass Solution {\n    private static final int MOD = 1_000_000_007;\n\n    public int countOfPairs(int[] nums) {\n        int prefixZeros = 0;\n        int n = nums.length;\n\n        // Calculate prefix zeros\n        for (int i = 1; i < n; i++) {\n            prefixZeros += Math.max(nums[i] - nums[i - 1], 0);\n        }\n\n        int row = n + 1;\n        int col = nums[n - 1] + 1 - prefixZeros;\n        \n        if (col <= 0) {\n            return 0;\n        }\n\n        // Initialize dp array\n        int[] dp = new int[col];\n        for (int i = 0; i < col; i++) {\n            dp[i] = 1;\n        }\n\n        // Fill dp array\n        for (int r = 1; r < row; r++) {\n            for (int c = 1; c < col; c++) {\n                dp[c] = (dp[c] + dp[c - 1]) % MOD;\n            }\n        }\n\n        return dp[col - 1];\n    }\n}\n\n```
['Java']