How to think about it..! Develop intution. n(logn) approach.
Initial thought\n\nHow could I find the maximum area? How to find some area which lies in the middle of the grid?\n\nDevelop thinking..\n\nFirst, do not get ove
**Initial thought**\n\nHow could I find the maximum area? How to find some area which lies in the middle of the grid?\n\n**Develop thinking..**\n\nFirst, do not get overwhelmed by looking at the visual picture. You should know, the problem is made to solve.\nYou just have to change the thinking process.\n\nNow, approach:\nArea consitutes of **length * width**\n\nYou see the problem now becomes simple.\nFor maximizing the area, you need to **maximize the length and width**.\n\nSo, now you just have to find the maximum gap from given horizotal and vertical cuts.\n\nThanks everyone!\n\nPlease consider **upvoting** if you llike to see more posts like this.\n\n**Code**\n\n```\n    int maxArea(int h, int w, vector<int>& horizontal, vector<int>& vertical) {\n        sort(begin(horizontal), end(horizontal));              // n(logn)\n        sort(begin(vertical), end(vertical));                       // n(logn)\n        \n        long long hmx = 0, vmx = 0, prev = 0;\n        \n        for(auto i: horizontal)                                          // O(n)  \n            hmx = max(hmx, i - prev), prev = i;\n        hmx = max(hmx, h - prev);\n        \n        prev = 0;\n        for(auto i: vertical)                                              // O(n)  \n            vmx = max(vmx, i - prev), prev = i;\n        vmx = max(vmx, w - prev);\n        \n        int mod = 1e9 + 7;\n        return hmx * vmx % mod;\n    }\n```\n\n**Time**: O(nlogn)  (due to sorting)\n**Space**: O(1)\n\nSome more related problems:\n\n[1232. Check If It Is a Straight Line](https://leetcode.com/problems/check-if-it-is-a-straight-line/)\n[658. Find K Closest Elements](https://leetcode.com/problems/find-k-closest-elements/)\n[1521. Find a Value of a Mysterious Function Closest to Target](https://leetcode.com/problems/find-a-value-of-a-mysterious-function-closest-to-target/)
['Greedy', 'C']