From 8ecfaf8ed1e440e1d0acddf8013c7109eab3152c Mon Sep 17 00:00:00 2001 From: Won Joon Thomas Choi <113500771+724thomas@users.noreply.github.com> Date: Thu, 19 Nov 2026 22:35:02 +0900 Subject: [PATCH 1/4] Create 1802. Maximum Value at a Given Index in a Bounded Array.py --- ...ue at a Given Index in a Bounded Array.py" | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 "leetcode3/\354\265\234\354\233\220\354\244\200/1802. Maximum Value at a Given Index in a Bounded Array.py" diff --git "a/leetcode3/\354\265\234\354\233\220\354\244\200/1802. Maximum Value at a Given Index in a Bounded Array.py" "b/leetcode3/\354\265\234\354\233\220\354\244\200/1802. Maximum Value at a Given Index in a Bounded Array.py" new file mode 100644 index 00000000..fc453525 --- /dev/null +++ "b/leetcode3/\354\265\234\354\233\220\354\244\200/1802. Maximum Value at a Given Index in a Bounded Array.py" @@ -0,0 +1,52 @@ +# + +''' +1. 아이디어 : +- index 값이 1씩 오를때 얼마나 오르는지 O(1)로 계산해야한다. +왼쪽, 오른쪽 등차 계산: (첫 숫자 + 마지막 숫자) x 갯수 / 2 +계산하는 거리가 실제 존재하는 숫자보다 많은 경우 등차 계산으로는 초과하는 숫자들까지 포함되어서 else로 분기. +- 거리를 1씩 올리게 되면 (n)이고 시간초과. 이분탐색으로 logn으로 찾는다 + +2. 시간복잡도 : + O(logn) + +3. 자료구조/알고리즘 : +이분탐색 + +''' +class Solution: + def maxValue(self, n: int, index: int, maxSum: int) -> int: + + + left_nums = index + right_nums = n-index-1 + + def get_total(distance, count): + if distance > count: + return (distance - 1 + distance - count) * count // 2 + else: + return distance * (distance - 1) // 2 - (distance - count - 1) + + def calculate_total(distance): + left_total = get_total(distance, left_nums) + right_total = get_total(distance, right_nums) + return left_total + distance + right_total + + + ans = 0 + + left = 1 + right = maxSum + 1 + + while left <= right: + mid = (left + right) // 2 + + if calculate_total(mid) <= maxSum: + ans = mid + left = mid + 1 + else: + right = mid - 1 + + return ans + + From 53ab19d7536415fcbc02d9c28ca0e044ea50bc93 Mon Sep 17 00:00:00 2001 From: Won Joon Thomas Choi <113500771+724thomas@users.noreply.github.com> Date: Thu, 19 Nov 2026 22:35:17 +0900 Subject: [PATCH 2/4] Create 1828. Queries on Number of Points Inside a Circle.py --- ...es on Number of Points Inside a Circle.py" | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 "leetcode3/\354\265\234\354\233\220\354\244\200/1828. Queries on Number of Points Inside a Circle.py" diff --git "a/leetcode3/\354\265\234\354\233\220\354\244\200/1828. Queries on Number of Points Inside a Circle.py" "b/leetcode3/\354\265\234\354\233\220\354\244\200/1828. Queries on Number of Points Inside a Circle.py" new file mode 100644 index 00000000..e4d203f9 --- /dev/null +++ "b/leetcode3/\354\265\234\354\233\220\354\244\200/1828. Queries on Number of Points Inside a Circle.py" @@ -0,0 +1,28 @@ +# + +''' +1. 아이디어 : +완전 탐색으로 쿼리마다 점들의 거리를 계산한다. + +2. 시간복잡도 : + O(n * m) + +3. 자료구조/알고리즘 : +- + +''' +class Solution: + def countPoints(self, points: list[list[int]], queries: list[list[int]]) -> list[int]: + + def get_distance(x1, y1, x2, y2): + return (abs(x1-x2) ** 2 + abs(y1-y2) ** 2) ** (1/2) + + ans = [] + + for x1, y1, r in queries: + count = 0 + for x2, y2 in points: + if get_distance(x1, y1, x2, y2) <= r: + count += 1 + ans.append(count) + return ans From dcbeed23be8f731736862027713558d2a2ff9571 Mon Sep 17 00:00:00 2001 From: Won Joon Thomas Choi <113500771+724thomas@users.noreply.github.com> Date: Thu, 19 Nov 2026 22:39:14 +0900 Subject: [PATCH 3/4] Update 1802. Maximum Value at a Given Index in a Bounded Array.py --- .../1802. Maximum Value at a Given Index in a Bounded Array.py" | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git "a/leetcode3/\354\265\234\354\233\220\354\244\200/1802. Maximum Value at a Given Index in a Bounded Array.py" "b/leetcode3/\354\265\234\354\233\220\354\244\200/1802. Maximum Value at a Given Index in a Bounded Array.py" index fc453525..cefd4ece 100644 --- "a/leetcode3/\354\265\234\354\233\220\354\244\200/1802. Maximum Value at a Given Index in a Bounded Array.py" +++ "b/leetcode3/\354\265\234\354\233\220\354\244\200/1802. Maximum Value at a Given Index in a Bounded Array.py" @@ -25,7 +25,7 @@ def get_total(distance, count): if distance > count: return (distance - 1 + distance - count) * count // 2 else: - return distance * (distance - 1) // 2 - (distance - count - 1) + return distance * (distance - 1) // 2 + (count - distance + 1) def calculate_total(distance): left_total = get_total(distance, left_nums) From 8880e53fce836dbec0635f0ec6c5f37e8f73cc71 Mon Sep 17 00:00:00 2001 From: Won Joon Thomas Choi <113500771+724thomas@users.noreply.github.com> Date: Thu, 19 Nov 2026 22:41:45 +0900 Subject: [PATCH 4/4] Update 1802. Maximum Value at a Given Index in a Bounded Array.py --- ...1802. Maximum Value at a Given Index in a Bounded Array.py" | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git "a/leetcode3/\354\265\234\354\233\220\354\244\200/1802. Maximum Value at a Given Index in a Bounded Array.py" "b/leetcode3/\354\265\234\354\233\220\354\244\200/1802. Maximum Value at a Given Index in a Bounded Array.py" index cefd4ece..ae89c40e 100644 --- "a/leetcode3/\354\265\234\354\233\220\354\244\200/1802. Maximum Value at a Given Index in a Bounded Array.py" +++ "b/leetcode3/\354\265\234\354\233\220\354\244\200/1802. Maximum Value at a Given Index in a Bounded Array.py" @@ -23,7 +23,8 @@ def maxValue(self, n: int, index: int, maxSum: int) -> int: def get_total(distance, count): if distance > count: - return (distance - 1 + distance - count) * count // 2 + exceed = distance - count + return distance * (distance - 1) // 2 - exceed * (exceed - 1) // 2 else: return distance * (distance - 1) // 2 + (count - distance + 1)