JAVA ||  BASED ON CONCEPT OF "TWO SUM" || REALLY EASY SOLUTION ||FASTEST
\nclass Solution {\n    private int MOD = 1000000007;\n    public int numFactoredBinaryTrees(int[] arr) \n    {\n        int n = arr.length;\n        Arrays.sor
```\nclass Solution {\n    private int MOD = 1000000007;\n    public int numFactoredBinaryTrees(int[] arr) \n    {\n        int n = arr.length;\n        Arrays.sort(arr);\n        long[] dp = new long[n];\n        dp[0] = 1;\n        int ans = 0;\n        for (int idx = 1; idx < n; idx++)\n        {\n            int target = arr[idx];  //root \n            //===========================================\n            //EXACTLY SAME AS CONCEPT OF "TWO SUM" PROBLEM\n            \n            int i = 0, j = idx - 1; //two pointers for the "Two product" problem (same as Two Sum)\n            long ways = 1;\n            while(i <= j)\n            {\n                long prod = (((long)arr[i]) * (arr[j]));\n                if (prod == target) \n                {\n                    if (i == j) ways += (dp[i] * dp[j]) % MOD;\n                    else ways += ((dp[i] * dp[j]) * 2) % MOD;  \n                    //"*2" becoz 1) arr[i] is left child, arr[j] is right child\n                    //           2) arr[j] is left child, arr[i] is right child\n                    \n                    i++;\n                    j--;\n                }\n                else if (prod < target) i++;\n                else if (prod > target) j--;\n            }\n            \n            //============================================================\n            dp[idx] = ways;\n            ans  = (int)((ans + dp[idx]) % MOD); //add all the cases\n        }\n        return ans + 1;\n        \n    }\n}\n```
['Two Pointers', 'Dynamic Programming', 'Java']