Easiest JAVA solution using BigInteger class of Java 🙌🙌
Intuition\nFirst element is always fixed , now take rest elements and divide array in two arrays and repeat same process for each array. \n Describe your first 
# Intuition\nFirst element is always fixed , now take rest elements and divide array in two arrays and repeat same process for each array. \n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nTake first element as root, not divide array in two parts which contains lesser elments and greater elements than the root node respectively and put in new array in same order. \nNow except first place we can use rest all places to put the elements, we will find this by taking any required place ant put it in order, now we repeat the same operation for the two divided arrays. \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)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nimport java.math.BigInteger;\nclass Solution {\n    int ans = 0;\n    BigInteger[] b = new BigInteger[1001];\n    BigInteger m = new BigInteger("1000000007");\n    BigInteger m2 = factorial(1000);\n    public int numOfWays(int[] nums) {\n        b[0] = BigInteger.ONE;\n        b[1] = BigInteger.ONE;\n        int n = nums.length;\n        if(n<=2) return 0;\n        return (solve(nums).subtract(BigInteger.ONE)).mod(m).intValue();\n    }\n    public BigInteger solve(int[] nums){\n        int n = nums.length;\n        if(n<=2) return BigInteger.ONE;;\n        int[] ar , br;\n        int l = 0, h = 0;\n        for(int i=1;i<nums.length;i++){\n            if(nums[i]>nums[0]){\n                h++;\n            }else{\n                l++;\n            }\n        }\n        ar = new int[h];\n        br = new int[l];\n        h = 0;\n        l = 0;\n        for(int i=1;i<nums.length;i++){\n            if(nums[i]>nums[0]){\n                ar[h] = nums[i];\n                h++;\n            }else{\n                br[l] = nums[i];\n                l++;\n            }\n        }\n        return ((b[n-1].divide(b[h]).divide(b[n-1-h]).mod(m).multiply(solve(ar)).multiply(solve(br)).mod(m))).mod(m);\n    }\n    public BigInteger factorial(int num){\n    if (num<=1)\n        return BigInteger.ONE;\n    else\n        return b[num] = factorial(num-1).multiply(BigInteger.valueOf(num));\n    }\n}\n```
['Java']