Best solution, Beats 100% in Java.
\n\n# Code\n\nclass Solution {\n        public int countOfPairs(int[] A) {\n        int n = A.length, m = 1001, mod = 1000000007, dp[] = new int[m];\n        Ar
\n\n# Code\n```\nclass Solution {\n        public int countOfPairs(int[] A) {\n        int n = A.length, m = 1001, mod = 1000000007, dp[] = new int[m];\n        Arrays.fill(dp, 1);\n\n        for (int i = 1; i < n; ++i) {\n            int d = Math.max(0, A[i] - A[i - 1]), dp2[] = new int[m];\n            for (int j = d; j < A[i] + 1; ++j) {\n                dp2[j] = ((j > 0 ? dp2[j - 1] : 0) + dp[j - d]) % mod;\n            }\n            dp = dp2;\n        }\n\n        int res = 0;\n        for (int j = 0; j <= A[n - 1]; ++j)\n            res = (res + dp[j]) % mod;\n        return res;\n    }\n}\n```\n\n
['Array', 'Dynamic Programming', 'Java']