Two Passes |  Easy & Clean Code |  C ++
If we get the largest edge in vertical direction and same in the horizontal direction , the largest piece will be the multiple of these ( length x width ). This
If we get the largest edge in vertical direction and same in the horizontal direction , the largest piece will be the multiple of these ( length x width ). This can be done in two linear passes , one to find out the edge in horizontal direction and other in vertical direction .\nSince the order of the cuts are not given correctly , we also need to sort the vector.\n\n**Time Complexity : O(n logn)  *(n is* `max( | verticalCuts | , | horizontalCuts | )`\nSpace Complexity : O(1)**\n```\n        sort(horizontalCuts.begin(),horizontalCuts.end());   // sort both vectors so that cuts are consecutive\n        sort(verticalCuts.begin(),verticalCuts.end());\n        \n        \n        int maxV = max(w - *(verticalCuts.end()-1),verticalCuts[0])  ;  // maxV stores the longest edge in horizontal direction(as cuts are vertical)\n        for(int i =1;i<verticalCuts.size();i++){\n            maxV = max(maxV,(verticalCuts[i]-verticalCuts[i-1]));\n        }\n        \n         int maxh = max(h - *(horizontalCuts.end()-1),horizontalCuts[0]) ; // this is max(cakes\'s end - last cut , first cut - cake\'s start(start is 0) )\n        for(int i =1;i<horizontalCuts.size();i++){\n            maxh = max(maxh,(horizontalCuts[i]-horizontalCuts[i-1]));\n        }\n        \n        \n        int mod = 1e9+7;\n        return  ((long)(maxV%mod)*(maxh%mod))%mod;\n        \n```
['C']