Java Solution | Permutations & Combinations
Code\n\nclass Solution {\n    public int numOfWays(int[] nums) {\n        List<Integer> arr=new ArrayList<>();\n        for(int i=0; i<nums.length; i++) {\n    
# Code\n```\nclass Solution {\n    public int numOfWays(int[] nums) {\n        List<Integer> arr=new ArrayList<>();\n        for(int i=0; i<nums.length; i++) {\n            arr.add(nums[i]);\n        }\n\n        int n=nums.length;\n        pascal=new long[n+1][n+1];\n        pascal[0][0]=1;\n        //nCr = n-1Cr-1 + n-1Cr\n        for(int i=1; i<=n; i++) {\n            pascal[i][0]=1;\n            for(int j=1; j<i; j++) {\n                pascal[i][j] = (pascal[i-1][j-1]+pascal[i-1][j])%MOD;\n            }\n            pascal[i][i]=1;\n        }\n        /*\n        //print pascal\'s triangle for debugging\n        // for(int i=0;i<pascal.length;i++) \n            // System.out.println(Arrays.toString(pascal[i]));\n        */\n\n        return (int)(util(arr)-1);\n    }\n\n    private final long MOD=(long)1e9+7;\n\n    //calculating nCR using pascal\'s triangle because factorial will cause long overflow\n    private long pascal[][];\n    private long nCr(int n, int r) { \n        return pascal[n][r];\n    }\n    \n    private long util(List<Integer> arr) {\n        if(arr.size()<=2) return 1;\n\n        List<Integer> left=new ArrayList<>();\n        List<Integer> right=new ArrayList<>();\n        int root=arr.get(0);\n        for(int child: arr) {\n            if(child==root) continue;\n            if(child<root) {\n                left.add(child);\n            }else {\n                right.add(child);\n            }\n        }\n\n        int x=left.size();\n        int y=right.size();\n        long combi=nCr(x+y, x)%MOD;\n        long get=(util(left)*util(right))%MOD;\n        long ret=(combi*get)%MOD;\n        return ret;\n    }\n}\n```
['Divide and Conquer', 'Binary Search Tree', 'Combinatorics', 'Binary Tree', 'Java']