From e4d050ecded5904832e13330da6354e9f32cccc9 Mon Sep 17 00:00:00 2001 From: freakin23 Date: Sun, 27 Oct 2024 13:10:50 +0530 Subject: [PATCH 1/6] correct TC --- content/5_Plat/Geo_Pri.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/5_Plat/Geo_Pri.mdx b/content/5_Plat/Geo_Pri.mdx index a5e1404c0f..a51f8891e5 100644 --- a/content/5_Plat/Geo_Pri.mdx +++ b/content/5_Plat/Geo_Pri.mdx @@ -493,7 +493,7 @@ points from the beginning of the sorted array, thus the array of angles should b ## Implementation -**Time Complexity:** $\mathcal{O}(N)$ +**Time Complexity:** $\mathcal{O}(N \log N)$ From 67c558f1b07ee9b45238c5121418275b2f3c8fce Mon Sep 17 00:00:00 2001 From: freakin23 Date: Sun, 27 Oct 2024 13:14:16 +0530 Subject: [PATCH 2/6] correct the code --- content/5_Plat/Geo_Pri.mdx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/content/5_Plat/Geo_Pri.mdx b/content/5_Plat/Geo_Pri.mdx index a51f8891e5..1c6e905113 100644 --- a/content/5_Plat/Geo_Pri.mdx +++ b/content/5_Plat/Geo_Pri.mdx @@ -514,6 +514,10 @@ class Solution { angles.push_back(atan2(p[1] - location[1], p[0] - location[0])); } + if (angles.empty()) { + return extra; + } + // Sort agngles sort(angles.begin(), angles.end()); // Duplicate the array and add 2*PI to the angles From 4458c9a1845a7841d374d476864bd3593117d85e Mon Sep 17 00:00:00 2001 From: freakin23 Date: Sun, 27 Oct 2024 13:19:20 +0530 Subject: [PATCH 3/6] typo --- content/5_Plat/Geo_Pri.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/5_Plat/Geo_Pri.mdx b/content/5_Plat/Geo_Pri.mdx index 1c6e905113..afb365a0d4 100644 --- a/content/5_Plat/Geo_Pri.mdx +++ b/content/5_Plat/Geo_Pri.mdx @@ -518,7 +518,7 @@ class Solution { return extra; } - // Sort agngles + // Sort angles sort(angles.begin(), angles.end()); // Duplicate the array and add 2*PI to the angles for (int i = 0; i < (int)points.size(); i++) { From b110baef11cc580745fb0f4bd7f6cbb1f2114e8c Mon Sep 17 00:00:00 2001 From: freakin23 Date: Sun, 27 Oct 2024 13:20:19 +0530 Subject: [PATCH 4/6] py sol for Maximum number of visible points --- content/5_Plat/Geo_Pri.mdx | 41 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/content/5_Plat/Geo_Pri.mdx b/content/5_Plat/Geo_Pri.mdx index afb365a0d4..9cc056c8a8 100644 --- a/content/5_Plat/Geo_Pri.mdx +++ b/content/5_Plat/Geo_Pri.mdx @@ -540,6 +540,47 @@ class Solution { ``` + + +```py +class Solution: + def visiblePoints(self, points: List[List[int]], angle: int, location: List[int]) -> int: + extra = 0 + angles = [] + + for p in points: + # Ignore points identical to location + if p == location: + extra += 1 + continue + + # Take the arctg in radians + angles.append(atan2(p[1] - location[1], p[0] - location[0])) + + if len(angles) == 0: + return extra + + # Sort angles + angles.sort() + + # Duplicate the array and add 2*PI to the angles + angles += [a + 2 * pi for a in angles] + + ans = 0 + angle_radians = pi * angle / 180 + + l = 0 + # Sliding window + for r in range(len(angles)): + # Pop all the points out of the field of view + while angles[r] - angles[l] > angle_radians: + l += 1 + ans = max(ans, r - l + 1) + + return ans + extra +``` + + From 210ae3663a280c2d1af9746d34b2946e73944a73 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 27 Oct 2024 07:58:19 +0000 Subject: [PATCH 5/6] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- content/5_Plat/Geo_Pri.mdx | 74 +++++++++++++++++++------------------- 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/content/5_Plat/Geo_Pri.mdx b/content/5_Plat/Geo_Pri.mdx index 9cc056c8a8..8647fcc687 100644 --- a/content/5_Plat/Geo_Pri.mdx +++ b/content/5_Plat/Geo_Pri.mdx @@ -514,9 +514,7 @@ class Solution { angles.push_back(atan2(p[1] - location[1], p[0] - location[0])); } - if (angles.empty()) { - return extra; - } + if (angles.empty()) { return extra; } // Sort angles sort(angles.begin(), angles.end()); @@ -544,40 +542,42 @@ class Solution { ```py class Solution: - def visiblePoints(self, points: List[List[int]], angle: int, location: List[int]) -> int: - extra = 0 - angles = [] - - for p in points: - # Ignore points identical to location - if p == location: - extra += 1 - continue - - # Take the arctg in radians - angles.append(atan2(p[1] - location[1], p[0] - location[0])) - - if len(angles) == 0: - return extra - - # Sort angles - angles.sort() - - # Duplicate the array and add 2*PI to the angles - angles += [a + 2 * pi for a in angles] - - ans = 0 - angle_radians = pi * angle / 180 - - l = 0 - # Sliding window - for r in range(len(angles)): - # Pop all the points out of the field of view - while angles[r] - angles[l] > angle_radians: - l += 1 - ans = max(ans, r - l + 1) - - return ans + extra + def visiblePoints( + self, points: List[List[int]], angle: int, location: List[int] + ) -> int: + extra = 0 + angles = [] + + for p in points: + # Ignore points identical to location + if p == location: + extra += 1 + continue + + # Take the arctg in radians + angles.append(atan2(p[1] - location[1], p[0] - location[0])) + + if len(angles) == 0: + return extra + + # Sort angles + angles.sort() + + # Duplicate the array and add 2*PI to the angles + angles += [a + 2 * pi for a in angles] + + ans = 0 + angle_radians = pi * angle / 180 + + l = 0 + # Sliding window + for r in range(len(angles)): + # Pop all the points out of the field of view + while angles[r] - angles[l] > angle_radians: + l += 1 + ans = max(ans, r - l + 1) + + return ans + extra ``` From c41535eaaa67a5f7ba7946cb8fe5aadc8e4b0316 Mon Sep 17 00:00:00 2001 From: Kevin Sheng <55369003+SansPapyrus683@users.noreply.github.com> Date: Sun, 27 Oct 2024 07:37:24 -0700 Subject: [PATCH 6/6] Update Geo_Pri.mdx --- content/5_Plat/Geo_Pri.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/5_Plat/Geo_Pri.mdx b/content/5_Plat/Geo_Pri.mdx index 8647fcc687..22434c6ab7 100644 --- a/content/5_Plat/Geo_Pri.mdx +++ b/content/5_Plat/Geo_Pri.mdx @@ -557,7 +557,7 @@ class Solution: # Take the arctg in radians angles.append(atan2(p[1] - location[1], p[0] - location[0])) - if len(angles) == 0: + if not angles: return extra # Sort angles