Leetcode Weekly Contest 427 All Solutions

  Рет қаралды 750

Arnab Bhadra

Arnab Bhadra

Күн бұрын

Пікірлер: 5
@ArnabBhadra02
@ArnabBhadra02 28 күн бұрын
Soln2: class Solution: def maxRectangleArea(self, points): n = len(points) point_set = {f"{x},{y}" for x, y in points} max_area = -1 for i in range(n): for j in range(i + 1, n): x1, y1 = points[i] x2, y2 = points[j] if x1 != x2 and y1 != y2: corner1 = f"{x1},{y2}" corner2 = f"{x2},{y1}" if corner1 in point_set and corner2 in point_set: if self.is_rectangle_valid(points, x1, y1, x2, y2): area = abs(x1 - x2) * abs(y1 - y2) max_area = max(max_area, area) return max_area def is_rectangle_valid(self, points, x1, y1, x2, y2): min_x, max_x = min(x1, x2), max(x1, x2) min_y, max_y = min(y1, y2), max(y1, y2) for px, py in points: if ((min_x < px < max_x and min_y < py < max_y) or ((px == min_x or px == max_x) and min_y < py < max_y) or ((py == min_y or py == max_y) and min_x < px < max_x)): return False return True
@ArnabBhadra02
@ArnabBhadra02 28 күн бұрын
Soln3: class Solution: def maxSubarraySum(self, nums, k): n = len(nums) prefix_sum = [0] * (n + 1) for i in range(n): prefix_sum[i + 1] = prefix_sum[i] + nums[i] min_prefix_sum = [float('inf')] * k max_sum = float('-inf') for i in range(n + 1): remainder = i % k if i >= k: max_sum = max(max_sum, prefix_sum[i] - min_prefix_sum[remainder]) min_prefix_sum[remainder] = min(min_prefix_sum[remainder], prefix_sum[i]) return 0 if max_sum == float('-inf') else max_sum
@ArnabBhadra02
@ArnabBhadra02 28 күн бұрын
Soln1: class Solution: def constructTransformedArray(self, nums): n = len(nums) result = [] for i, steps in enumerate(nums): index = (i + steps % n + n) % n result.append(nums[index]) return result
@SRUTHI.28
@SRUTHI.28 28 күн бұрын
soln 4 pls
@heytopg
@heytopg 28 күн бұрын
class Solution: def maxRectangleArea(self, xCoord, yCoord): points = list(zip(xCoord, yCoord)) point_set = set(points) max_area = -1 for i in range(len(points)): for j in range(i + 1, len(points)): x1, y1 = points[i] x2, y2 = points[j] if x1 != x2 and y1 != y2: corner1 = (x1, y2) corner2 = (x2, y1) if corner1 in point_set and corner2 in point_set: area = abs(x1 - x2) * abs(y1 - y2) if self.is_rectangle_valid(point_set, x1, y1, x2, y2): max_area = max(max_area, area) return max_area def is_rectangle_valid(self, point_set, x1, y1, x2, y2): min_x, max_x = min(x1, x2), max(x1, x2) min_y, max_y = min(y1, y2), max(y1, y2) for px, py in point_set: if min_x < px < max_x and min_y < py < max_y: return False return True check for xCoord = [1, 1, 3, 3, 1, 3] yCoord = [1, 3, 1, 3, 2, 2]
My Brain after 569 Leetcode Problems
7:50
NeetCode
Рет қаралды 2,7 МЛН
LeetCode was HARD until I Learned these 15 Patterns
13:00
Ashish Pratap Singh
Рет қаралды 698 М.
BAYGUYSTAN | 1 СЕРИЯ | bayGUYS
36:55
bayGUYS
Рет қаралды 1,9 МЛН
The Best Band 😅 #toshleh #viralshort
00:11
Toshleh
Рет қаралды 22 МЛН
Winning LeetCode Weekly Contest 201
12:07
William Lin (tmwilliamlin168)
Рет қаралды 133 М.
BRAIN ROT | Why You Are Losing Control Of Your Brain?
17:40
Aevy TV
Рет қаралды 522 М.
3381. Maximum Subarray Sum With Length Divisible by K (Leetcode Medium)
18:34
Programming Live with Larry
Рет қаралды 607
How I Mastered Data Structures and Algorithms in 8 Weeks
15:46
Aman Manazir
Рет қаралды 146 М.
I'm 24. If you're 14-23 please watch this...
6:37
Tharun Speaks
Рет қаралды 660 М.
Zig for Impatient Devs
9:48
Isaac Harris-Holt
Рет қаралды 111 М.