C++/Java Maximum Gap Between Cuts
The biggest piece is formed by the biggest vertical, and the biggest horizontal gap between cuts.\n\nSo, we sort cuts, and find the maximum gap. The gap for the
The biggest piece is formed by the biggest vertical, and the biggest horizontal gap between cuts.\n\nSo, we sort cuts, and find the maximum gap. The gap for the first and the last cut is defined by the cake\'s edge.\n\n**C++**\n```cpp\nint maxArea(int h, int w, vector<int>& hCuts, vector<int>& vCuts) {\n    sort(begin(hCuts), end(hCuts));\n    sort(begin(vCuts), end(vCuts));\n    auto max_h = max(hCuts[0], h - hCuts.back());\n    auto max_v = max(vCuts[0], w - vCuts.back());\n    for (auto i = 0; i < hCuts.size() - 1; ++i)\n        max_h = max(max_h, hCuts[i + 1] - hCuts[i]);\n    for (auto i = 0; i < vCuts.size() - 1; ++i)\n        max_v = max(max_v, vCuts[i + 1] - vCuts[i]);        \n    return (long)max_h * max_v % 1000000007;\n}\n```\n\n**Java**\n```java\npublic int maxArea(int h, int w, int[] hCuts, int[] vCuts) {\n    Arrays.sort(hCuts);\n    Arrays.sort(vCuts);\n    int max_h = Math.max(hCuts[0], h - hCuts[hCuts.length - 1]);\n    int max_v = Math.max(vCuts[0], w - vCuts[vCuts.length - 1]);  \n    for (int i = 0; i < hCuts.length - 1; ++i)\n        max_h = Math.max(max_h, hCuts[i + 1] - hCuts[i]);\n    for (int i = 0; i < vCuts.length - 1; ++i)\n        max_v = Math.max(max_v, vCuts[i + 1] - vCuts[i]);        \n    return (int)((long)max_h * max_v % 1000000007);        \n}\n```\n**Complexity Analysis**\n- Time: O(v log v + h log h), where *v* and *h* are the number of vertical and horizontal cuts.\n- Memory: O(1), plus memory required by the sort algorithm (from O(log n) to O(n), where *n* is the number of elements we sort).
[]