{"id":7582,"date":"2020-10-31T13:29:59","date_gmt":"2020-10-31T20:29:59","guid":{"rendered":"https:\/\/zxi.mytechroad.com\/blog\/?p=7582"},"modified":"2020-10-31T13:30:51","modified_gmt":"2020-10-31T20:30:51","slug":"leetcode-1637-widest-vertical-area-between-two-points-containing-no-points","status":"publish","type":"post","link":"https:\/\/zxi.mytechroad.com\/blog\/geometry\/leetcode-1637-widest-vertical-area-between-two-points-containing-no-points\/","title":{"rendered":"\u82b1\u82b1\u9171 LeetCode 1637. Widest Vertical Area Between Two Points Containing No Points"},"content":{"rendered":"\n<p>Given&nbsp;<code>n<\/code>&nbsp;<code>points<\/code>&nbsp;on a 2D plane where&nbsp;<code>points[i] = [x<sub>i<\/sub>, y<sub>i<\/sub>]<\/code>, Return<em>&nbsp;the&nbsp;<strong>widest vertical area<\/strong>&nbsp;between two points such that no points are inside the area.<\/em><\/p>\n\n\n\n<p>A&nbsp;<strong>vertical area<\/strong>&nbsp;is an area of fixed-width extending infinitely along the y-axis (i.e., infinite height). The&nbsp;<strong>widest vertical area<\/strong>&nbsp;is the one with the maximum width.<\/p>\n\n\n\n<p>Note that points&nbsp;<strong>on the edge<\/strong>&nbsp;of a vertical area&nbsp;<strong>are not<\/strong>&nbsp;considered included in the area.<\/p>\n\n\n\n<p><strong>Example 1:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/assets.leetcode.com\/uploads\/2020\/09\/19\/points3.png\" alt=\"\"\/><\/figure>\n\n\n\n<p>\u200b<\/p>\n\n\n\n<pre class=\"wp-block-preformatted;crayon:false\"><strong>Input:<\/strong> points = [[8,7],[9,9],[7,4],[9,7]]\n<strong>Output:<\/strong> 1\n<strong>Explanation:<\/strong> Both the red and the blue area are optimal.\n<\/pre>\n\n\n\n<p><strong>Example 2:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted;crayon:false\"><strong>Input:<\/strong> points = [[3,1],[9,0],[1,0],[1,4],[5,3],[8,8]]\n<strong>Output:<\/strong> 3\n<\/pre>\n\n\n\n<p><strong>Constraints:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><code>n == points.length<\/code><\/li><li><code>2 &lt;= n &lt;= 10<sup>5<\/sup><\/code><\/li><li><code>points[i].length == 2<\/code><\/li><li><code>0 &lt;= x<sub>i<\/sub>, y<sub>i<\/sub>&nbsp;&lt;= 10<sup>9<\/sup><\/code><\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Solution: Sort by x coordinates<\/strong><\/h2>\n\n\n\n<p>Time complexity: O(nlogn)<br>Space complexity: O(n)<\/p>\n\n\n\n<div class=\"responsive-tabs\">\n<h2 class=\"tabtitle\">C++<\/h2>\n<div class=\"tabcontent\">\n\n<pre lang=\"c++\">\nclass Solution {\npublic:\n  int maxWidthOfVerticalArea(vector<vector<int>>& points) {\n    sort(begin(points), end(points), [](const auto& p1, const auto& p2) {\n      return p1[0] != p2[0] ? p1[0] < p2[0] : p1[1] < p2[1];\n    });\n    int ans = 0;\n    for (int i = 1; i < points.size(); ++i)\n      ans = max(ans, points[i][0] - points[i - 1][0]);\n    return ans;\n  }\n};\n<\/pre>\n<\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Given&nbsp;n&nbsp;points&nbsp;on a 2D plane where&nbsp;points[i] = [xi, yi], Return&nbsp;the&nbsp;widest vertical area&nbsp;between two points such that no points are inside the area. A&nbsp;vertical area&nbsp;is an area&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[127],"tags":[284,177,23],"class_list":["post-7582","post","type-post","status-publish","format-standard","hentry","category-geometry","tag-geometry","tag-medium","tag-sort","entry","simple"],"_links":{"self":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts\/7582","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/comments?post=7582"}],"version-history":[{"count":2,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts\/7582\/revisions"}],"predecessor-version":[{"id":7584,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts\/7582\/revisions\/7584"}],"wp:attachment":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/media?parent=7582"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/categories?post=7582"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/tags?post=7582"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}