From fa323b85f09d5313042251f40fb09aed05daf480 Mon Sep 17 00:00:00 2001 From: Yash <75321458+Yashwanth137@users.noreply.github.com> Date: Sun, 19 May 2024 13:53:28 +0530 Subject: [PATCH 01/11] Update README_EN.md --- .../README_EN.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/solution/3000-3099/3068.Find the Maximum Sum of Node Values/README_EN.md b/solution/3000-3099/3068.Find the Maximum Sum of Node Values/README_EN.md index 9e04d8750514d..fd675a7a0f36d 100644 --- a/solution/3000-3099/3068.Find the Maximum Sum of Node Values/README_EN.md +++ b/solution/3000-3099/3068.Find the Maximum Sum of Node Values/README_EN.md @@ -97,7 +97,17 @@ It can be shown that 9 is the maximum achievable sum of values. #### Python3 ```python - +class Solution: + def maximumValueSum(self, nums: List[int], k: int, edges: List[List[int]]) -> int: + n = len(nums) + res = [(x^k)-x for x in nums] + res.sort(reverse=True) + ans = sum(nums) + val = ans + for i in range(0, n-1, 2): + ans += res[i] + res[i+1] + val = max(ans, val) + return val ``` #### Java From 26a832fd75fd8413e0c8f4a70b26b9ce317d874a Mon Sep 17 00:00:00 2001 From: Yash <75321458+Yashwanth137@users.noreply.github.com> Date: Mon, 20 May 2024 15:05:57 +0530 Subject: [PATCH 02/11] Create Solution.py --- .../Solution.py | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 solution/3000-3099/3068.Find the Maximum Sum of Node Values/Solution.py diff --git a/solution/3000-3099/3068.Find the Maximum Sum of Node Values/Solution.py b/solution/3000-3099/3068.Find the Maximum Sum of Node Values/Solution.py new file mode 100644 index 0000000000000..40d274514a87c --- /dev/null +++ b/solution/3000-3099/3068.Find the Maximum Sum of Node Values/Solution.py @@ -0,0 +1,11 @@ +class Solution: + def maximumValueSum(self, nums: List[int], k: int, edges: List[List[int]]) -> int: + n = len(nums) + res = [(x^k)-x for x in nums] + res.sort(reverse=True) + ans = sum(nums) + val = ans + for i in range(0, n-1, 2): + ans += res[i] + res[i+1] + val = max(ans, val) + return val From 6df0339098d668be1a8756b6c20e9ccd8313eaab Mon Sep 17 00:00:00 2001 From: Yash <75321458+Yashwanth137@users.noreply.github.com> Date: Mon, 20 May 2024 15:06:50 +0530 Subject: [PATCH 03/11] Delete solution/3000-3099/3068.Find the Maximum Sum of Node Values/Solution.py --- .../Solution.py | 11 ----------- 1 file changed, 11 deletions(-) delete mode 100644 solution/3000-3099/3068.Find the Maximum Sum of Node Values/Solution.py diff --git a/solution/3000-3099/3068.Find the Maximum Sum of Node Values/Solution.py b/solution/3000-3099/3068.Find the Maximum Sum of Node Values/Solution.py deleted file mode 100644 index 40d274514a87c..0000000000000 --- a/solution/3000-3099/3068.Find the Maximum Sum of Node Values/Solution.py +++ /dev/null @@ -1,11 +0,0 @@ -class Solution: - def maximumValueSum(self, nums: List[int], k: int, edges: List[List[int]]) -> int: - n = len(nums) - res = [(x^k)-x for x in nums] - res.sort(reverse=True) - ans = sum(nums) - val = ans - for i in range(0, n-1, 2): - ans += res[i] + res[i+1] - val = max(ans, val) - return val From 0f2a6f0a6ed72dcb9ad1304bc98074003bb0f69a Mon Sep 17 00:00:00 2001 From: Yash <75321458+Yashwanth137@users.noreply.github.com> Date: Mon, 20 May 2024 15:07:32 +0530 Subject: [PATCH 04/11] Create Solution.py --- .../Solution.py | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 solution/3000-3099/3068.Find the Maximum Sum of Node Values/Solution.py diff --git a/solution/3000-3099/3068.Find the Maximum Sum of Node Values/Solution.py b/solution/3000-3099/3068.Find the Maximum Sum of Node Values/Solution.py new file mode 100644 index 0000000000000..40d274514a87c --- /dev/null +++ b/solution/3000-3099/3068.Find the Maximum Sum of Node Values/Solution.py @@ -0,0 +1,11 @@ +class Solution: + def maximumValueSum(self, nums: List[int], k: int, edges: List[List[int]]) -> int: + n = len(nums) + res = [(x^k)-x for x in nums] + res.sort(reverse=True) + ans = sum(nums) + val = ans + for i in range(0, n-1, 2): + ans += res[i] + res[i+1] + val = max(ans, val) + return val From dcc4843e5edf5c8af18f045acdf9f6686cf55c4d Mon Sep 17 00:00:00 2001 From: Yash <75321458+Yashwanth137@users.noreply.github.com> Date: Sat, 13 Jul 2024 21:45:50 +0530 Subject: [PATCH 05/11] Create Solution.py --- .../2751.Robot Collisions/Solution.py | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 solution/2700-2799/2751.Robot Collisions/Solution.py diff --git a/solution/2700-2799/2751.Robot Collisions/Solution.py b/solution/2700-2799/2751.Robot Collisions/Solution.py new file mode 100644 index 0000000000000..6415e99fc3727 --- /dev/null +++ b/solution/2700-2799/2751.Robot Collisions/Solution.py @@ -0,0 +1,24 @@ +class Solution: + def survivedRobotsHealths(self, positions: List[int], healths: List[int], directions: str) -> List[int]: + temp = {x: i for i,x in enumerate(positions)} + + stack = [] + for x in sorted(positions): + i = temp[x] + + if directions[i] == "R": + stack.append(i) + else: + while stack and healths[i]: + j = stack.pop() + if healths[i] > healths[j]: + healths[j] = 0 + healths[i] -= 1 + elif healths[i] < healths[j]: + healths[i] = 0 + healths[j] -= 1 + stack.append(j) + else: + healths[i] = healths[j] = 0 + + return [item for item in healths if item > 0] From d466d436d3d6659cddf3c35f9e0720a48ef5954a Mon Sep 17 00:00:00 2001 From: Yash <75321458+Yashwanth137@users.noreply.github.com> Date: Sat, 13 Jul 2024 21:47:19 +0530 Subject: [PATCH 06/11] Update README_EN.md --- .../2751.Robot Collisions/README_EN.md | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/solution/2700-2799/2751.Robot Collisions/README_EN.md b/solution/2700-2799/2751.Robot Collisions/README_EN.md index f624b21067c2e..4bf8202571caa 100644 --- a/solution/2700-2799/2751.Robot Collisions/README_EN.md +++ b/solution/2700-2799/2751.Robot Collisions/README_EN.md @@ -90,7 +90,30 @@ tags: #### Python3 ```python - +class Solution: + def survivedRobotsHealths(self, positions: List[int], healths: List[int], directions: str) -> List[int]: + temp = {x: i for i,x in enumerate(positions)} + + stack = [] + for x in sorted(positions): + i = temp[x] + + if directions[i] == "R": + stack.append(i) + else: + while stack and healths[i]: + j = stack.pop() + if healths[i] > healths[j]: + healths[j] = 0 + healths[i] -= 1 + elif healths[i] < healths[j]: + healths[i] = 0 + healths[j] -= 1 + stack.append(j) + else: + healths[i] = healths[j] = 0 + + return [item for item in healths if item > 0] ``` #### Java From 009c504812970413d0164fea40ff933936d71e46 Mon Sep 17 00:00:00 2001 From: Yash <75321458+Yashwanth137@users.noreply.github.com> Date: Sat, 13 Jul 2024 21:47:50 +0530 Subject: [PATCH 07/11] Update README.md --- .../2700-2799/2751.Robot Collisions/README.md | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/solution/2700-2799/2751.Robot Collisions/README.md b/solution/2700-2799/2751.Robot Collisions/README.md index ed0bb46be82ec..0f8fb742950e7 100644 --- a/solution/2700-2799/2751.Robot Collisions/README.md +++ b/solution/2700-2799/2751.Robot Collisions/README.md @@ -90,7 +90,30 @@ tags: #### Python3 ```python - +class Solution: + def survivedRobotsHealths(self, positions: List[int], healths: List[int], directions: str) -> List[int]: + temp = {x: i for i,x in enumerate(positions)} + + stack = [] + for x in sorted(positions): + i = temp[x] + + if directions[i] == "R": + stack.append(i) + else: + while stack and healths[i]: + j = stack.pop() + if healths[i] > healths[j]: + healths[j] = 0 + healths[i] -= 1 + elif healths[i] < healths[j]: + healths[i] = 0 + healths[j] -= 1 + stack.append(j) + else: + healths[i] = healths[j] = 0 + + return [item for item in healths if item > 0] ``` #### Java From 791cfb8332e7c841dbe98760fd8c70e303ee155e Mon Sep 17 00:00:00 2001 From: Yash <75321458+Yashwanth137@users.noreply.github.com> Date: Sat, 30 Nov 2024 22:33:15 +0530 Subject: [PATCH 08/11] Create Solution.py --- .../Solution.py | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 solution/2000-2099/2097.Valid Arrangement of Pairs/Solution.py diff --git a/solution/2000-2099/2097.Valid Arrangement of Pairs/Solution.py b/solution/2000-2099/2097.Valid Arrangement of Pairs/Solution.py new file mode 100644 index 0000000000000..f4b716c18f91f --- /dev/null +++ b/solution/2000-2099/2097.Valid Arrangement of Pairs/Solution.py @@ -0,0 +1,26 @@ +class Solution: + def validArrangement(self, pairs): + graph = defaultdict(deque) + degree = defaultdict(int) + + for u, v in pairs: + graph[u].append(v) + degree[u] += 1 + degree[v] -= 1 + + start = pairs[0][0] + for node in graph: + if degree[node] > 0: + start = node + break + + path = [] + + def traverse(node): + while graph[node]: + traverse(graph[node].popleft()) + path.append(node) + + traverse(start) + path.reverse() + return [[path[i], path[i + 1]] for i in range(len(path) - 1)] From 4ec244ab2ac1f7764a68b7404585c1bcff78c41a Mon Sep 17 00:00:00 2001 From: Yash <75321458+Yashwanth137@users.noreply.github.com> Date: Sat, 30 Nov 2024 22:34:06 +0530 Subject: [PATCH 09/11] Update README_EN.md --- .../README_EN.md | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/solution/2000-2099/2097.Valid Arrangement of Pairs/README_EN.md b/solution/2000-2099/2097.Valid Arrangement of Pairs/README_EN.md index d6634170a35e5..7ebe2684b2d79 100644 --- a/solution/2000-2099/2097.Valid Arrangement of Pairs/README_EN.md +++ b/solution/2000-2099/2097.Valid Arrangement of Pairs/README_EN.md @@ -87,6 +87,32 @@ end1 = 1 == 1 = start2 #### Python3 ```python +class Solution: + def validArrangement(self, pairs): + graph = defaultdict(deque) + degree = defaultdict(int) + + for u, v in pairs: + graph[u].append(v) + degree[u] += 1 + degree[v] -= 1 + + start = pairs[0][0] + for node in graph: + if degree[node] > 0: + start = node + break + + path = [] + + def traverse(node): + while graph[node]: + traverse(graph[node].popleft()) + path.append(node) + + traverse(start) + path.reverse() + return [[path[i], path[i + 1]] for i in range(len(path) - 1)] ``` From 8b825706cbcd639e21a4b768160630b393f8cc8f Mon Sep 17 00:00:00 2001 From: Yash <75321458+Yashwanth137@users.noreply.github.com> Date: Sat, 30 Nov 2024 22:34:17 +0530 Subject: [PATCH 10/11] Update README_EN.md --- .../README_EN.md | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/solution/2000-2099/2097.Valid Arrangement of Pairs/README_EN.md b/solution/2000-2099/2097.Valid Arrangement of Pairs/README_EN.md index d6634170a35e5..7ebe2684b2d79 100644 --- a/solution/2000-2099/2097.Valid Arrangement of Pairs/README_EN.md +++ b/solution/2000-2099/2097.Valid Arrangement of Pairs/README_EN.md @@ -87,6 +87,32 @@ end1 = 1 == 1 = start2 #### Python3 ```python +class Solution: + def validArrangement(self, pairs): + graph = defaultdict(deque) + degree = defaultdict(int) + + for u, v in pairs: + graph[u].append(v) + degree[u] += 1 + degree[v] -= 1 + + start = pairs[0][0] + for node in graph: + if degree[node] > 0: + start = node + break + + path = [] + + def traverse(node): + while graph[node]: + traverse(graph[node].popleft()) + path.append(node) + + traverse(start) + path.reverse() + return [[path[i], path[i + 1]] for i in range(len(path) - 1)] ``` From 82b1a86f0356e45870c7919f86bf6f846d69c691 Mon Sep 17 00:00:00 2001 From: Yash <75321458+Yashwanth137@users.noreply.github.com> Date: Sat, 30 Nov 2024 22:38:12 +0530 Subject: [PATCH 11/11] Update README.md --- .../2097.Valid Arrangement of Pairs/README.md | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/solution/2000-2099/2097.Valid Arrangement of Pairs/README.md b/solution/2000-2099/2097.Valid Arrangement of Pairs/README.md index 1fa6c8e20ed4e..ae3cdc696f5b7 100644 --- a/solution/2000-2099/2097.Valid Arrangement of Pairs/README.md +++ b/solution/2000-2099/2097.Valid Arrangement of Pairs/README.md @@ -89,6 +89,32 @@ end1 = 1 == 1 = start2 #### Python3 ```python +class Solution: + def validArrangement(self, pairs): + graph = defaultdict(deque) + degree = defaultdict(int) + + for u, v in pairs: + graph[u].append(v) + degree[u] += 1 + degree[v] -= 1 + + start = pairs[0][0] + for node in graph: + if degree[node] > 0: + start = node + break + + path = [] + + def traverse(node): + while graph[node]: + traverse(graph[node].popleft()) + path.append(node) + + traverse(start) + path.reverse() + return [[path[i], path[i + 1]] for i in range(len(path) - 1)] ```