question_slug stringlengths 3 77 | title stringlengths 1 183 | slug stringlengths 12 45 | summary stringlengths 1 160 ⌀ | author stringlengths 2 30 | certification stringclasses 2
values | created_at stringdate 2013-10-25 17:32:12 2025-04-12 09:38:24 | updated_at stringdate 2013-10-25 17:32:12 2025-04-12 09:38:24 | hit_count int64 0 10.6M | has_video bool 2
classes | content stringlengths 4 576k | upvotes int64 0 11.5k | downvotes int64 0 358 | tags stringlengths 2 193 | comments int64 0 2.56k |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
recover-the-original-array | [Python]||Set||Binary-search | pythonsetbinary-search-by-u_knw_who-7kd6 | Create a set with all possible values of K and iterate over the list for each element to find corresponding high one \n\n\ndef recoverArray(self, nums):\n\n | u_knw_who | NORMAL | 2022-05-17T02:41:33.729641+00:00 | 2022-05-17T02:41:33.729669+00:00 | 130 | false | Create a set with all possible values of K and iterate over the list for each element to find corresponding high one \n\n```\ndef recoverArray(self, nums):\n```\n \n def bsearch(x,nums):\n n = len(nums)\n low = 0\n end = n-1\n \n while low<=end:\n ... | 0 | 0 | ['Binary Tree', 'Ordered Set'] | 0 |
recover-the-original-array | [C++] try out the candidates of K. | c-try-out-the-candidates-of-k-by-fzh-4ej3 | \n\n\n// 2122. Recover the Original Array\nclass Solution {\n static inline bool isEven(int n) {\n return (n & 1) == 0;\n }\n\n static tuple<boo | fzh | NORMAL | 2022-04-26T23:37:02.671144+00:00 | 2022-04-26T23:37:02.671175+00:00 | 138 | false | \n\n```\n// 2122. Recover the Original Array\nclass Solution {\n static inline bool isEven(int n) {\n return (n & 1) == 0;\n }\n\n static tuple<bool, vector<int>> isGoodK(const int k, const vector<int>& A) {\n unordered_multiset nset(A.begin(), A.end());\n vector<int> originals;\n o... | 0 | 0 | ['C'] | 0 |
recover-the-original-array | Ruby Solution | ruby-solution-by-rosssg-p5pb | ```\n# @param {Integer[]} nums\n# @return {Integer[]}\ndef recover_array(nums)\n nums.sort!\n uniques = nums.uniq\n start = uniques.shift\n tests = | rosssg | NORMAL | 2022-04-09T01:45:23.229495+00:00 | 2022-04-09T01:45:23.229521+00:00 | 30 | false | ```\n# @param {Integer[]} nums\n# @return {Integer[]}\ndef recover_array(nums)\n nums.sort!\n uniques = nums.uniq\n start = uniques.shift\n tests = []\n n = nums.length / 2\n for i in 0...uniques.length\n tests << (uniques[i] - start) / 2 if (uniques[i] - start) % 2 == 0 \n end\n \n \n... | 0 | 0 | [] | 0 |
recover-the-original-array | O(n^2) | on2-by-sammos-6j3y | If we have the lowest value of the lower array and the lowest value of the higher array we can recunstruct it in linear time. We just keep adding the next lowes | sammos | NORMAL | 2022-02-01T17:36:37.446291+00:00 | 2022-02-01T17:41:40.380420+00:00 | 98 | false | If we have the lowest value of the lower array and the lowest value of the higher array we can recunstruct it in linear time. We just keep adding the next lowest from the set + k to the result and remove the lowest and the lowest + 2 * k from the set.\nWe already know the lowest value of the lower array, because it mus... | 0 | 0 | [] | 0 |
recover-the-original-array | C# AC - check if number and number+2*k exists | c-ac-check-if-number-and-number2k-exists-urbb | checking if the array is valid for K logic is similar to these 2 problems. so solve these first\nhttps://leetcode.com/problems/find-original-array-from-doubled- | rajanikanthr | NORMAL | 2022-02-01T00:27:22.974136+00:00 | 2022-02-01T01:58:55.516785+00:00 | 84 | false | checking if the array is valid for K logic is similar to these 2 problems. so **solve these first**\nhttps://leetcode.com/problems/find-original-array-from-doubled-array/discuss/1735246/c-ac-check-frequencies\nhttps://leetcode.com/problems/array-of-doubled-pairs/discuss/1735322/C-AC-check-frequencies\n\n\nIf we check e... | 0 | 0 | [] | 0 |
find-the-maximum-sum-of-node-values | Greedy Sacrifice | greedy-sacrifice-by-votrubac-neo2 | \nIn a tree, we can freely change any even number of nodes.\n\n> I got this intuitioin by drawing a few trees and trying to change some nodes without changing t | votrubac | NORMAL | 2024-03-02T16:01:04.812227+00:00 | 2024-03-02T17:45:00.872504+00:00 | 6,195 | false | \nIn a tree, we can freely change any even number of nodes.\n\n> I got this intuitioin by drawing a few trees and trying to change some nodes without changing the others.\n \nSo, we count nodes that we want to change (where n ^ k > n).\n \nIf the count is even, we just return the best `sum`.\n \nIf the count i... | 181 | 0 | ['C', 'Python3'] | 22 |
find-the-maximum-sum-of-node-values | Extreme detailed Explanation, that could ever exists | extreme-detailed-explanation-that-could-62lfv | So, the first thing you should notice that, this problem doesn\'t have any big examples. So, whenever you see something like this, you should have your examples | hi-malik | NORMAL | 2024-05-19T01:41:33.631994+00:00 | 2024-05-19T20:37:23.204299+00:00 | 15,114 | false | So, the first thing you should notice that, this problem doesn\'t have any big examples. So, whenever you see something like this, you should have your examples, because working on a example, will give you some hints. Because the Questioner doesn\'t wanted you to get the hint\'s easily just via there examples!\n\nLet\'... | 169 | 1 | ['C', 'Python', 'Java'] | 33 |
find-the-maximum-sum-of-node-values | [Java/C++/Python] Edges are Useless | javacpython-edges-are-useless-by-lee215-4onw | TLDR\nToo long don\'t read:\n\nThe shape of tree doesn\'t matter.\nedges are useless.\nEach operation, change two nodes,\nso in the end, we change whichever eve | lee215 | NORMAL | 2024-03-02T16:07:32.003459+00:00 | 2024-03-02T16:35:15.662443+00:00 | 4,965 | false | # **TLDR**\nToo long don\'t read:\n\nThe shape of tree doesn\'t matter.\nedges are useless.\nEach operation, change two nodes,\nso in the end, we change whichever even nodes.\n<br>\n\n# **Intuition**\nAfter the previous excercise on the tree,\nI was confident to handle dfs on the tree.\n\nNow each node can XOR or stay ... | 82 | 1 | ['C', 'Python', 'Java'] | 15 |
find-the-maximum-sum-of-node-values | ✅Detailed Explanation🔥2 Approaches🔥🔥Extremely Simple and effective🔥🔥🔥 | detailed-explanation2-approachesextremel-7lof | \uD83C\uDFAFProblem Explanation:\nYou are given an undirected tree with n nodes numbered from 0 to n - 1 where each node has some value (see nums) and array nod | heir-of-god | NORMAL | 2024-05-19T06:06:44.731931+00:00 | 2024-05-19T10:10:56.771402+00:00 | 9,324 | false | # \uD83C\uDFAFProblem Explanation:\nYou are given an undirected tree with ```n``` nodes numbered from **0 to n - 1** where each node has some value (see ```nums```) and array ```nodes``` which represents edges beetwen nodes. You can perform XOR operation with number ```k``` any number of times on any two nodes which ha... | 70 | 0 | ['Dynamic Programming', 'Greedy', 'Bit Manipulation', 'Tree', 'C', 'Python', 'C++', 'Java', 'Python3', 'JavaScript'] | 17 |
find-the-maximum-sum-of-node-values | C++ || Greedy Solution || Visualized || Comprehensive explanation | c-greedy-solution-visualized-comprehensi-1p0w | Welcome to a comprehensive solution which will leave all your doubts cleared. \n\n# Intuition\n\nThere are two things we need to keep in mind in this problem\n- | akramshafeek | NORMAL | 2024-03-02T18:44:51.480830+00:00 | 2024-03-03T02:15:04.661831+00:00 | 2,273 | false | Welcome to a comprehensive solution which will leave all your doubts cleared. \n\n# Intuition\n\nThere are two things we need to keep in mind in this problem\n- `XOR` and `Tree`\n- The tree is connected, which means we can reach any node from any other node freely. There always exists a path between any two nodes.\n- `... | 53 | 0 | ['Greedy', 'Bit Manipulation', 'Tree', 'C++'] | 9 |
find-the-maximum-sum-of-node-values | 🔥 🔥 🔥 Fastest (100%) || Video Explanation || Easy to understand 🔥 🔥 🔥 | fastest-100-video-explanation-easy-to-un-hu6o | Detailed Approach Explained in Video Here\n\n\n\n\n# Intuition\n- The intuition behind this approach is that XOR operations on elements in the list can either i | bhanu_bhakta | NORMAL | 2024-05-19T00:18:38.257845+00:00 | 2024-05-19T05:32:54.660449+00:00 | 7,634 | false | # [Detailed Approach Explained in Video Here](https://www.youtube.com/watch?v=bmwQtId0Z2Q)\n\n\n\n\n# Intuition\n- The intuition behind this approach is that XOR operation... | 32 | 2 | ['C++', 'Java', 'Go', 'Python3', 'JavaScript'] | 10 |
find-the-maximum-sum-of-node-values | DP recurion+memo->tabular->space O(1)||119ms Beats 100% | dp-recurionmemo-tabular-space-o1119ms-be-8kfj | Intuition\n Describe your first thoughts on how to solve this problem. \nQuestion is hard. Use DP to solve. edges is ignored!\nDP recurion+memo->tabular->optimi | anwendeng | NORMAL | 2024-05-19T02:53:34.119038+00:00 | 2024-05-19T13:30:49.677710+00:00 | 1,910 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nQuestion is hard. Use DP to solve. `edges` is ignored!\nDP recurion+memo->tabular->optimized space\n# Approach\n<!-- Describe your approach to solving the problem. -->\nLet `0` be the root.\nLet `f(i, c)=dp[i][c]` denote the max sum from ... | 23 | 0 | ['Dynamic Programming', 'C++', 'Python3'] | 8 |
find-the-maximum-sum-of-node-values | Beats 99% ️🔥Python3 || Greedy solution with intuition and explanation ✅ | beats-99-python3-greedy-solution-with-in-7k7c | Intuition\nAt first, the problem seems to constrain us to picking nodes from the given edges and consider them pairwise. We need a few key observations to appro | reas0ner | NORMAL | 2024-05-19T00:54:39.359576+00:00 | 2024-05-19T01:24:04.725598+00:00 | 1,409 | false | # Intuition\nAt first, the problem seems to constrain us to picking nodes from the given edges and consider them pairwise. We need a few key observations to approach this problem:\n\n1. **XOR with k is like a toggle:** Either the node value will increase, or it will decrease. Observe that (x ^ a) ^ a = x. We want the ... | 23 | 0 | ['Python3'] | 11 |
find-the-maximum-sum-of-node-values | Java O(n) time and O(1) extra memory DP simple solution | java-on-time-and-o1-extra-memory-dp-simp-mbgb | Intuition\nNote that you can actually pick any two nodes and apply the xor operation on them. \n\nYou can do this by applying the given operation consecutively | skinnysnakelimb | NORMAL | 2024-03-02T16:03:38.230173+00:00 | 2024-03-02T19:23:01.810403+00:00 | 789 | false | # Intuition\nNote that **you can actually pick any two nodes and apply the xor operation on them**. \n\nYou can do this by applying the given operation consecutively on the chosen nodes and their parents, and then their parents and their parents\' parents and so on until the lowest common ancestor (lca), which would le... | 18 | 0 | ['Java'] | 6 |
find-the-maximum-sum-of-node-values | Beats 100% Video Solution | Java C++ Python | beats-100-video-solution-java-c-python-b-slrw | \n\nPython Beats 100%\n\n\n\nclass Solution {\n public long maximumValueSum(int[] nums, int k, int[][] edges) {\n \n int n = nums.length;\n | jeevankumar159 | NORMAL | 2024-05-19T02:13:40.822559+00:00 | 2024-05-19T02:13:40.822577+00:00 | 1,267 | false | <iframe width="560" height="315" src="https://www.youtube.com/embed/Wo-MsfKNoq4?si=EZxKeHwSqgw4VtTY" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen><... | 15 | 0 | ['C', 'Python', 'Java'] | 5 |
find-the-maximum-sum-of-node-values | ✅ Beat 100% | ✨ O(n) O(1) | 🏆 Most Efficient Solution | 💯 One pass with Easy to Read code. | beat-100-on-o1-most-efficient-solution-o-dcq4 | Intuition\n Describe your first thoughts on how to solve this problem. \n * Each node is like a toggle button, when we push it, its value becomes x XOR k; when | hero080 | NORMAL | 2024-03-04T05:14:04.514450+00:00 | 2024-03-04T05:14:46.549072+00:00 | 322 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n * Each node is like a toggle button, when we push it, its value becomes `x XOR k`; when we push it again, it\'s value becomes `x XOR k XOR k = x`. Yes it recovers its original value!\n * We are allowed to push two buttons that are adja... | 11 | 0 | ['Math', 'C++'] | 4 |
find-the-maximum-sum-of-node-values | 🔥 All 4 DP Solutions 🔥 Easiest Hard Problem | all-4-dp-solutions-easiest-hard-problem-7r7xv | Intuition\nAny node say A can be paired with any other node say B by pairing all the nodes from A to B path resulting in double xor of in between elements which | bhavik_11 | NORMAL | 2024-05-19T05:32:14.500066+00:00 | 2024-05-19T05:32:14.500102+00:00 | 562 | false | # Intuition\nAny node say A can be paired with any other node say B by pairing all the nodes from A to B path resulting in double xor of in between elements which doesn\'t change it, So the edges are useless here\n\n# Approach\nWe just need to keep sure that the nodes that are changed are even, as they were paired \nTh... | 10 | 0 | ['Dynamic Programming', 'Tree', 'C++'] | 1 |
find-the-maximum-sum-of-node-values | 🔥 BEATS 100% |✅ [ Java / C++ / Py / C / C# / JS / GO ] | beats-100-java-c-py-c-c-js-go-by-neoni_7-nb4f | Intuition\nTo maximize the sum of values of tree nodes, we need to carefully choose which edges to update and which to leave unchanged. Since updating an edge a | Neoni_77 | NORMAL | 2024-05-19T05:27:32.805038+00:00 | 2024-08-08T17:46:37.259319+00:00 | 890 | false | # Intuition\nTo maximize the sum of values of tree nodes, we need to carefully choose which edges to update and which to leave unchanged. Since updating an edge affects the values of both nodes connected by that edge, we need to consider the effect of each update on the overall sum of values.\n\n# Approach\n1. Initiali... | 8 | 1 | ['C', 'Python', 'C++', 'Java', 'Go', 'Python3', 'JavaScript', 'C#'] | 3 |
find-the-maximum-sum-of-node-values | Python 3 || 2 lines, maps, lambdas, and a filter || T/S: 91% / 77% | python-3-2-lines-maps-lambdas-and-a-filt-1s6q | You likely can get the spirit of this solution from others\' great explications that have already been posted.\n\nclass Solution:\n def maximumValueSum(self, | Spaulding_ | NORMAL | 2024-03-04T03:53:06.777276+00:00 | 2024-05-25T01:26:38.163885+00:00 | 207 | false | You likely can get the spirit of this solution from others\' great explications that have already been posted.\n```\nclass Solution:\n def maximumValueSum(self, nums: List[int], k: int, \n edges: List[List[int]]) -> int:\n\n dif = sorted(map(lambda x: x - (x^k), nums)) \n \... | 8 | 0 | ['Python3'] | 2 |
find-the-maximum-sum-of-node-values | O(n) || Greedy || Very easy to understand | on-greedy-very-easy-to-understand-by-ay7-5s8o | Intuition\n Describe your first thoughts on how to solve this problem. \nThe main intuition lies in the fact there is nothing to do with edges because it is com | AY73 | NORMAL | 2024-05-19T06:52:41.370751+00:00 | 2024-05-19T06:52:41.370779+00:00 | 506 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe main intuition lies in the fact there is nothing to do with edges because it is completely connected graph we can take any 2 nodes to do xor operation for suppose my tree is \na->b->c then for doing xor between a and c we have to do w... | 7 | 0 | ['Greedy', 'Bit Manipulation', 'C++'] | 4 |
find-the-maximum-sum-of-node-values | Video Explanation (Both DP & Greedy approach with Intuition) | video-explanation-both-dp-greedy-approac-sbh5 | Explanation\n\nClick here for the video\n\n# Code\n\ntypedef long long int ll;\n\nconst int N = 2e4+1;\n\nll dp[2][N];\nint par[N];\n\nclass Solution {\n \n | codingmohan | NORMAL | 2024-03-03T11:48:29.358983+00:00 | 2024-03-03T11:48:29.359038+00:00 | 292 | false | # Explanation\n\n[Click here for the video](https://youtu.be/BYF3vGQ49Zw)\n\n# Code\n```\ntypedef long long int ll;\n\nconst int N = 2e4+1;\n\nll dp[2][N];\nint par[N];\n\nclass Solution {\n \n ll K;\n vector<vector<int>> g;\n vector<ll> val;\n \n void CalculateParent(int root, int p) {\n par[r... | 7 | 0 | ['C++'] | 1 |
find-the-maximum-sum-of-node-values | O(N) approach | Easy | Tricky | C++ | Beat 100% | on-approach-easy-tricky-c-beat-100-by-al-yiki | Intuition\nwe firstly check from the given nodes which gives me profit. \nwe store nodes which gave us profit in x vector.\nand rest all to nx vector.\n\n# App | allrounderankit | NORMAL | 2024-03-02T16:16:39.332805+00:00 | 2024-03-02T17:45:15.662810+00:00 | 621 | false | # Intuition\nwe firstly check from the given nodes which gives me profit. \nwe store nodes which gave us profit in x vector.\nand rest all to nx vector.\n\n# Approach\n if size of x vector is EVEN than we can take XOR with all nodes because there will always exist 1 way to XOR them.\n\n\nbut if size is ODD than we hav... | 7 | 0 | ['Bit Manipulation', 'C++'] | 2 |
find-the-maximum-sum-of-node-values | Python | XOR | python-xor-by-khosiyat-2iwx | see the Successfully Accepted Submission\n\n# Code\n\nclass Solution:\n def maximumValueSum(self, nums: list[int], k: int, edges: list[list[int]]) -> int:\n | Khosiyat | NORMAL | 2024-05-19T04:46:48.718957+00:00 | 2024-05-19T04:46:48.718975+00:00 | 269 | false | [see the Successfully Accepted Submission](https://leetcode.com/problems/find-the-maximum-sum-of-node-values/submissions/1261915101/?envType=daily-question&envId=2024-05-19)\n\n# Code\n```\nclass Solution:\n def maximumValueSum(self, nums: list[int], k: int, edges: list[list[int]]) -> int:\n import sys\n ... | 6 | 0 | ['Python3'] | 2 |
find-the-maximum-sum-of-node-values | Ignore edge Greedy approach with explanation | clean code | [c++/java/python/go] | ignore-edge-greedy-approach-with-explana-gpoc | Intuition\n- This solution is based on we can xor operation on any pair of nodes irrespective of any direct edge between them. How??\n - For a parent node we | anupsingh556 | NORMAL | 2024-05-19T07:53:12.244963+00:00 | 2024-05-19T07:53:12.244995+00:00 | 243 | false | # Intuition\n- This solution is based on we can xor operation on any pair of nodes irrespective of any direct edge between them. How??\n - **For a parent node we can xor of it with any of its direct child or indirect child node.**\n - Suppose we have a parent node a with direct child b which has child c like a--... | 5 | 0 | ['C++'] | 3 |
find-the-maximum-sum-of-node-values | Surprisingly easy solution | surprisingly-easy-solution-by-winston_wo-zjtx | Code\n\npublic class Solution \n{\n public long MaximumValueSum(int[] nums, int k, int[][] edges) \n {\n long result = 0;\n\n foreach (long | winston_wolfe | NORMAL | 2024-03-02T19:27:59.728314+00:00 | 2024-03-02T19:27:59.728338+00:00 | 117 | false | # Code\n```\npublic class Solution \n{\n public long MaximumValueSum(int[] nums, int k, int[][] edges) \n {\n long result = 0;\n\n foreach (long num in nums)\n result += num;\n \n var queue = new PriorityQueue<int, int>();\n \n foreach (var num in nums)\n ... | 5 | 0 | ['C#'] | 2 |
find-the-maximum-sum-of-node-values | take, Not take || Easy✅ || Beats 100%🎯|| C++ | take-not-take-easy-beats-100-c-by-ajay_g-zmnq | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | Ajay_Gupta_01 | NORMAL | 2024-03-02T18:33:34.190349+00:00 | 2024-03-02T18:33:34.190380+00:00 | 446 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: O(n*2)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(n*2)\n<!-- Add your space complexity here, e.... | 5 | 0 | ['Dynamic Programming', 'Recursion', 'C++'] | 3 |
find-the-maximum-sum-of-node-values | [C++] XOR Again If Needed (Greedy) | c-xor-again-if-needed-greedy-by-awesome-dsinj | Intuition\n Describe your first thoughts on how to solve this problem. \n- Apply max(nums[i], nums[i] ^ k) for each element in the array\n- We can always change | pepe-the-frog | NORMAL | 2024-03-02T16:02:01.268776+00:00 | 2024-03-02T16:14:11.174581+00:00 | 481 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n- Apply `max(nums[i], nums[i] ^ k)` for each element in the array\n- We can always change the even number of times because this is a tree\n- If we changed the odd number of times, we need to XOR an integer again\n\n# Approach\n<!-- Descri... | 5 | 0 | ['Greedy', 'Bit Manipulation', 'Tree', 'C++'] | 3 |
find-the-maximum-sum-of-node-values | ✅ One Line Solution | one-line-solution-by-mikposp-fdux | (Disclaimer: this is not an example to follow in a real project - it is written for fun and training mostly)\n\n# Code #1.1 - One Line\nTime complexity: O(n). S | MikPosp | NORMAL | 2024-05-19T11:24:22.962885+00:00 | 2024-05-19T11:24:22.962910+00:00 | 537 | false | (Disclaimer: this is not an example to follow in a real project - it is written for fun and training mostly)\n\n# Code #1.1 - One Line\nTime complexity: $$O(n)$$. Space complexity: $$O(1)$$.\n```\nclass Solution:\n def maximumValueSum(self, a: List[int], k: int, e: List[List[int]]) -> int:\n return (r:=reduce... | 4 | 1 | ['Array', 'Greedy', 'Bit Manipulation', 'Tree', 'Python', 'Python3'] | 4 |
find-the-maximum-sum-of-node-values | Python3 || O(n) and O(1) TIME AND SPACE || May 19 2024 Daily | python3-on-and-o1-time-and-space-may-19-cqi1m | Intuition\nTo maximize the sum of the values of tree nodes, we need to carefully apply the XOR operation using the given integer \nk. The XOR operation can pote | praneelpa | NORMAL | 2024-05-19T00:23:03.091435+00:00 | 2024-05-19T00:23:03.091460+00:00 | 444 | false | # Intuition\nTo maximize the sum of the values of tree nodes, we need to carefully apply the XOR operation using the given integer \nk. The XOR operation can potentially increase the value of a node, but we must consider how to maximize the overall sum by selectively applying this operation to the tree\'s edges. The go... | 4 | 0 | ['Array', 'Dynamic Programming', 'Greedy', 'Bit Manipulation', 'Tree', 'Sorting', 'Python3'] | 4 |
find-the-maximum-sum-of-node-values | ✅ O(n) DP + Greedy Solution in C++ | on-dp-greedy-solution-in-c-by-mayank_mot-l1s4 | Intuition\nTo find the maxSum for a subtree corresponding to a node curr, we need to find the maxSum for each children of curr in two cases:\nThe operation is p | Mayank_Motwani | NORMAL | 2024-03-03T12:37:11.665502+00:00 | 2024-03-03T12:38:28.553574+00:00 | 222 | false | # Intuition\nTo find the maxSum for a subtree corresponding to a node `curr`, we need to find the maxSum for each children of `curr` in two cases:\nThe operation is performed on the edge between them - `withOp`\nThe operation is not performed on the edge between them - `withoutOp`\n\nThe number of nodes whose values ca... | 4 | 0 | ['C++'] | 1 |
find-the-maximum-sum-of-node-values | C++ O(N) time, O(1) space | c-on-time-o1-space-by-user8383x-87uh | Intuition\n1. First idea is that we can xor any pair of nodes in the tree, not only directly connected ones. Explanation: the tree is connected (as per descript | user8383x | NORMAL | 2024-03-02T16:07:19.622723+00:00 | 2024-03-02T16:24:24.326310+00:00 | 265 | false | # Intuition\n1. First idea is that we can xor any pair of nodes in the tree, not only directly connected ones. Explanation: the tree is connected (as per description), thus, there always exists a path between nodes `a` and `b`: `a -> ... -> b`. Short reminder: `x^k^k = x`.By xor\'ing every pair on the path, we have:\n ... | 4 | 0 | ['C++'] | 1 |
find-the-maximum-sum-of-node-values | 💥 Memory beats 100% [EXPLAINED] | memory-beats-100-explained-by-r9n-bv2i | IntuitionThe problem asks for finding the maximum value sum based on a sequence of numbers where you can either choose the number as is or apply a bitwise XOR o | r9n | NORMAL | 2025-01-30T02:43:08.351728+00:00 | 2025-01-30T02:43:08.351728+00:00 | 5 | false | # Intuition
The problem asks for finding the maximum value sum based on a sequence of numbers where you can either choose the number as is or apply a bitwise XOR operation with a given constant k. The XOR operation flips the bits of the number and may change its value, so we need to decide whether to include the number... | 3 | 0 | ['Math', 'Dynamic Programming', 'Backtracking', 'Greedy', 'Bit Manipulation', 'Depth-First Search', 'Graph', 'Binary Search Tree', 'Sorting', 'Kotlin'] | 0 |
find-the-maximum-sum-of-node-values | 👏💯PYTHON 🎉|| JS 🎉|| JAVA 🎉|| 🔥🔥 Best Visualization ||✅ New Question || 🫰Only Sorting | python-js-java-best-visualization-new-qu-w4xs | Screenshot \uD83C\uDF89\n\n\n\n\n---\n\n\n# Intuition \uD83E\uDD14\n Describe your first thoughts on how to solve this problem. \n maximum possible sum of th | Prakhar-002 | NORMAL | 2024-05-19T11:09:51.569021+00:00 | 2024-05-19T12:07:33.425167+00:00 | 119 | false | # Screenshot \uD83C\uDF89\n\n\n\n\n---\n\n\n# Intuition \uD83E\uDD14\n<!-- Describe your first thoughts on how to solve this problem. -->\n maximum possible sum of the values \n\n Let\'s understand the... | 3 | 0 | ['Array', 'Dynamic Programming', 'Greedy', 'Bit Manipulation', 'Tree', 'Sorting', 'Python', 'Java', 'JavaScript'] | 1 |
find-the-maximum-sum-of-node-values | Easy C++ Solution | Beats 100 💯✅ | easy-c-solution-beats-100-by-shobhitkush-msn4 | Intuition\n Describe your first thoughts on how to solve this problem. \nThe problem involves maximizing the sum of a vector v of integers by performing a bitwi | shobhitkushwaha1406 | NORMAL | 2024-05-19T05:00:05.470385+00:00 | 2024-05-19T05:00:05.470407+00:00 | 421 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe problem involves maximizing the sum of a vector v of integers by performing a bitwise XOR operation with an integer k on some or all of the elements. The aim is to determine the optimal approach to achieve the maximum possible sum of ... | 3 | 0 | ['Bit Manipulation', 'Tree', 'C++'] | 1 |
find-the-maximum-sum-of-node-values | DFS from any vertex | dfs-from-any-vertex-by-avulanov-aqu9 | Intuition\nEven number of XOR is the same as no XOR, odd number of XOR is the same as 1 XOR. We can do DFS on the graph and try to find max between two cases. I | avulanov | NORMAL | 2024-05-19T03:09:02.664579+00:00 | 2024-05-19T03:09:02.664619+00:00 | 230 | false | # Intuition\nEven number of XOR is the same as no XOR, odd number of XOR is the same as 1 XOR. We can do DFS on the graph and try to find max between two cases. It does not matter which node to start with. This one is hard to prove, but its easy to see empyrically once code is ready.\n\n# Approach\nDFS on the graph wit... | 3 | 0 | ['Python3'] | 1 |
find-the-maximum-sum-of-node-values | [C++ / Go] Greedily from Leaves and Sacrifice Chosen Root - O(n) time + O(1) space | c-go-greedily-from-leaves-and-sacrifice-z51bk | Intuition\n## Optimize Greedily from Leaves and Sacrifice Chosen Root\n- Greedily optimize from leaves:\n - Each node can either be num or num ^ k. To maximi | mikazuki4712 | NORMAL | 2024-05-19T02:03:30.001130+00:00 | 2024-05-19T02:28:27.294422+00:00 | 301 | false | # Intuition\n## Optimize Greedily from Leaves and Sacrifice Chosen Root\n- Greedily optimize from leaves:\n - Each node can either be `num` or `num ^ k`. To maximize the sum, we choose the more optimal value between `num` and `num ^ k`.\n - Start the optimization process from the leaves, and move towards the pare... | 3 | 0 | ['Greedy', 'C++', 'Go'] | 1 |
find-the-maximum-sum-of-node-values | Fastest execution || Beats 100% users with java & typescript || python3 || C++ || Greedy | fastest-execution-beats-100-users-with-j-o7tp | Approach\nGreedy\n\n# Complexity\n- Time complexity: O(n)\n\n- Space complexity: O(1)\n\n# Explanation\n1. Class Definition:\n\n- We define a class Solution whi | SanketSawant18 | NORMAL | 2024-05-19T00:31:52.349323+00:00 | 2024-05-19T00:31:52.349352+00:00 | 256 | false | # Approach\nGreedy\n\n# Complexity\n- Time complexity: O(n)\n\n- Space complexity: O(1)\n\n# Explanation\n1. **Class Definition:**\n\n- We define a class Solution which contains the method maximumValueSum.\n2. **Method Signature:**\n\n- **The method maximumValueSum takes three parameters:**\n - int[] nums: An array ... | 3 | 0 | ['Array', 'Dynamic Programming', 'Greedy', 'Tree', 'C++', 'Java', 'TypeScript', 'Python3'] | 1 |
find-the-maximum-sum-of-node-values | 🏆💢💯 Faster✅💯 Lesser🧠 🎯 C++✅Python3🐍✅Java✅C✅Python🐍✅💥🔥💫Explained☠💥🔥 Beats 💯 | faster-lesser-cpython3javacpythonexplain-j9kd | Intuition\n\n\n\njava []\nclass Solution {\n public long maximumValueSum(int[] A, int k, int[][] edges) {\n long res = 0;\n int d = 1 << 30, c | Edwards310 | NORMAL | 2024-03-02T16:35:55.355491+00:00 | 2024-05-19T00:10:00.275520+00:00 | 111 | false | # Intuition\n\n\n![Screenshot 2024-03-02 21570... | 3 | 0 | ['Array', 'Dynamic Programming', 'Greedy', 'Bit Manipulation', 'Tree', 'C', 'Python', 'C++', 'Java', 'Python3'] | 3 |
find-the-maximum-sum-of-node-values | Greedy Approach O(N) Solution || C++ 🔥💯 | greedy-approach-on-solution-c-by-_rishab-7tm2 | Maximum Value Sum\n\n## Problem Statement\n\nGiven a tree represented by nums and edges, and an integer k, we need to maximize the sum of the values in nums aft | _Rishabh_96 | NORMAL | 2024-05-19T13:16:07.496844+00:00 | 2024-05-19T13:16:07.496874+00:00 | 220 | false | # Maximum Value Sum\n\n## Problem Statement\n\nGiven a tree represented by `nums` and `edges`, and an integer `k`, we need to maximize the sum of the values in `nums` after potentially transforming each value using the bitwise XOR operation with `k`. Specifically, for each value `num` in `nums`, we can either leave it ... | 2 | 0 | ['Array', 'Greedy', 'C++'] | 0 |
find-the-maximum-sum-of-node-values | Swift solution | swift-solution-by-azm819-6gs7 | Complexity\n- Time complexity: O(n)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(1)\n Add your space complexity here, e.g. O(n) \n\n# Co | azm819 | NORMAL | 2024-05-19T10:47:19.921568+00:00 | 2024-05-19T10:47:19.921600+00:00 | 27 | false | # Complexity\n- Time complexity: $$O(n)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(1)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n func maximumValueSum(_ nums: [Int], _ k: Int, _: [[Int]]) -> Int {\n var minPositiveDiff: ... | 2 | 0 | ['Array', 'Greedy', 'Bit Manipulation', 'Tree', 'Swift'] | 0 |
find-the-maximum-sum-of-node-values | Beginner friendly || Nice approach || i take help | beginner-friendly-nice-approach-i-take-h-kfee | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | Saksham_chaudhary_2002 | NORMAL | 2024-05-19T06:23:07.100364+00:00 | 2024-05-19T06:23:07.100402+00:00 | 148 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 2 | 0 | ['Array', 'Dynamic Programming', 'Greedy', 'Bit Manipulation', 'Tree', 'Sorting', 'Python3'] | 1 |
find-the-maximum-sum-of-node-values | Easy To Understand | easy-to-understand-by-heerkshah434-l9kn | Intuition\n Describe your first thoughts on how to solve this problem. \n- I will try to XOR every element such that the sum increases.\n- XORing an element twi | heerkshah434 | NORMAL | 2024-05-19T06:20:04.933726+00:00 | 2024-05-19T06:20:04.933757+00:00 | 90 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n- I will try to XOR every element such that the sum increases.\n- XORing an element twice will not affect the sum.\n- I can choose any two nodes to apply XOR regardless of whether there is an edge between them or not, as reaching that nod... | 2 | 0 | ['Dynamic Programming', 'Greedy', 'Bit Manipulation', 'Tree', 'C++'] | 1 |
find-the-maximum-sum-of-node-values | javascript Six Lines Only Method with explanation | javascript-six-lines-only-method-with-ex-v6hs | Intuition\n##### we do not need list of agdes at all\nIt is easy to demonstrate that we can perform an operation between any nums[u] and nums[v] with multiple o | charnavoki | NORMAL | 2024-05-19T05:44:45.921134+00:00 | 2024-05-19T05:59:11.242498+00:00 | 55 | false | # Intuition\n##### we do not need list of `agdes` at all\nIt is easy to demonstrate that we can perform an operation between any `nums[u]` and `nums[v]` with multiple operations, even if there is no direct edge between them.\n##### calculate `(nums[u] ^ k) - nums[u]` for each number\nAfter calculations, we received an ... | 2 | 0 | ['JavaScript'] | 1 |
find-the-maximum-sum-of-node-values | AB | ab-by-anil-budamakuntla-1fae | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | ANIL-BUDAMAKUNTLA | NORMAL | 2024-05-19T05:13:34.490221+00:00 | 2024-05-19T05:13:34.490249+00:00 | 3 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 2 | 0 | ['C++'] | 2 |
find-the-maximum-sum-of-node-values | Greedy Delta | Sorting | Python | greedy-delta-sorting-python-by-pragya_23-za9p | Complexity\n- Time complexity: O(nlogn)\n\n- Space complexity: O(n)\n\n# Code\n\nclass Solution:\n def maximumValueSum(self, nums: List[int], k: int, edges: | pragya_2305 | NORMAL | 2024-05-19T04:56:41.995787+00:00 | 2024-05-19T04:56:41.995818+00:00 | 146 | false | # Complexity\n- Time complexity: O(nlogn)\n\n- Space complexity: O(n)\n\n# Code\n```\nclass Solution:\n def maximumValueSum(self, nums: List[int], k: int, edges: List[List[int]]) -> int:\n delta = [(num^k)-num for num in nums]\n delta.sort(reverse=True)\n ans = sum(nums)\n\n for i in rang... | 2 | 0 | ['Array', 'Greedy', 'Bit Manipulation', 'Tree', 'Sorting', 'Python', 'Python3'] | 2 |
find-the-maximum-sum-of-node-values | Dart solution | dart-solution-by-dartist-lzhv | Code\n\nclass Solution {\n int maximumValueSum(List<int> nums, int k, List<List<int>> edges) {\n int d = 1 << 30, cnt = 0, sum = 0;\n for (int num in num | Dartist | NORMAL | 2024-05-19T00:55:55.818116+00:00 | 2024-05-19T00:55:55.818136+00:00 | 19 | false | # Code\n```\nclass Solution {\n int maximumValueSum(List<int> nums, int k, List<List<int>> edges) {\n int d = 1 << 30, cnt = 0, sum = 0;\n for (int num in nums) {\n final b = num ^ k;\n sum += max(num, b);\n cnt ^= num < b ? 1 : 0;\n d = min(d, (num - b).abs());\n }\n return sum - d * c... | 2 | 0 | ['Dart'] | 0 |
find-the-maximum-sum-of-node-values | :: Kotlin :: Don't be distracted from the tree! | kotlin-dont-be-distracted-from-the-tree-6qnue | \'edges\' is just a macguffin.\n\nAll information needed from the tree structure is\nThis means that an even number of xor operations can be performed.\n\n# Cod | znxkznxk1030 | NORMAL | 2024-05-03T05:03:39.372867+00:00 | 2024-05-03T05:03:39.372896+00:00 | 50 | false | # \'edges\' is just a macguffin.\n\nAll information needed from the tree structure is\nThis means that an even number of xor operations can be performed.\n\n# Code\n```\nclass Solution {\n fun maximumValueSum(nums: IntArray, k: Int, edges: Array<IntArray>): Long {\n var result = nums.map{it.toLong()}.sum()!!\... | 2 | 0 | ['Kotlin'] | 2 |
find-the-maximum-sum-of-node-values | One liner Solution || Python3 | one-liner-solution-python3-by-yangzen09-tn0g | One Liner--Best Solution \n\nApproach/Logic:-\n\n1- performing bitwise XOR operations on the input numbers and then applying some transformations to calculate t | YangZen09 | NORMAL | 2024-03-06T21:10:05.498582+00:00 | 2024-03-06T21:10:36.764799+00:00 | 77 | false | **One Liner--Best Solution** \n\n**Approach/Logic:-**\n\n1- performing bitwise XOR operations on the input numbers and then applying some transformations to calculate the maximum sum.\n\n2- calculates the XOR of each number with the given integer \'k\', sorts the resulting list, and then groups the elements in pairs.\n... | 2 | 1 | ['Python3'] | 1 |
find-the-maximum-sum-of-node-values | Easy C++ Solution || Using DP (Beats 100%) ✅✅ | easy-c-solution-using-dp-beats-100-by-ab-3gnr | Code\n\nclass Solution {\npublic:\n long long helper(int i,vector<int>& values,vector<vector<long long>> &dp,int n,int count,int k){\n if(i==n){\n | Abhi242 | NORMAL | 2024-03-04T17:18:01.502296+00:00 | 2024-03-04T17:18:01.502328+00:00 | 308 | false | # Code\n```\nclass Solution {\npublic:\n long long helper(int i,vector<int>& values,vector<vector<long long>> &dp,int n,int count,int k){\n if(i==n){\n if(count==0){\n return 0;\n }else{\n return INT_MIN;\n }\n }\n if(dp[i][count]!=-... | 2 | 0 | ['Dynamic Programming', 'Tree', 'Recursion', 'C++'] | 1 |
find-the-maximum-sum-of-node-values | GREEDY APPROACH (C++) BEATS 100 % | greedy-approach-c-beats-100-by-binarywiz-9r4k | Intuition\n Describe your first thoughts on how to solve this problem. \n\nFIRST INTUITION : The Moment One Reads XOR, These Properties Should Strike One\'s Bra | BinaryWizard_8 | NORMAL | 2024-03-03T05:47:43.973603+00:00 | 2024-03-03T16:03:32.732789+00:00 | 21 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n**FIRST INTUITION** : The Moment One Reads XOR, These Properties Should Strike One\'s Brain Immediately.\n\n1. a ^ a = 0.\n2. a ^ 0 = a.\n3. a ^ b = b ^ a. (Would Be Our Master-Stroke For XOR On Edges)\n\nIn This Entire Question, We Wil... | 2 | 0 | ['C++'] | 0 |
find-the-maximum-sum-of-node-values | Easy To Understand: Java Solution | easy-to-understand-java-solution-by-maya-kkbk | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | Mayank1733 | NORMAL | 2024-03-02T16:18:47.151861+00:00 | 2024-03-02T16:18:47.151884+00:00 | 265 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 2 | 0 | ['Java'] | 2 |
find-the-maximum-sum-of-node-values | C++ SOLUTION BEATS 100% DETAILED COMMENTS | c-solution-beats-100-detailed-comments-b-gjk4 | \n# Code\n\nclass Solution {\npublic:\n // Function to find the maximum value sum\n long long maximumValueSum(vector<int>& values, int k, vector<vector<in | Quinos2003 | NORMAL | 2024-03-02T16:04:13.146526+00:00 | 2024-03-02T16:04:13.146566+00:00 | 170 | false | \n# Code\n```\nclass Solution {\npublic:\n // Function to find the maximum value sum\n long long maximumValueSum(vector<int>& values, int k, vector<vector<int>>& edges) {\n int n = values.size(); // Number of nodes\n // Creating an adjacency list to represent the graph\n vector<int> adjacency... | 2 | 0 | ['C++'] | 1 |
find-the-maximum-sum-of-node-values | Insight into XOR | Full explaination with comments | insight-into-xor-full-explaination-with-ve5i6 | Intuition\n- XOR is associative and commutative, meaning we can shift around the order it\'s applied and still get the same result.\n- If a single node has the | awesson | NORMAL | 2024-03-02T16:03:53.793454+00:00 | 2024-03-03T00:03:40.299416+00:00 | 134 | false | # Intuition\n- XOR is associative and commutative, meaning we can shift around the order it\'s applied and still get the same result.\n- If a single node has the operation applied to it multiple times, (x XOR k) XOR k... each k XOR k pair will cancel to 0, and 0 XOR x is just x.\n - In other words, if we apply the ope... | 2 | 0 | ['Math', 'Tree', 'C++'] | 1 |
find-the-maximum-sum-of-node-values | C# | c-by-adchoudhary-m3fl | Code | adchoudhary | NORMAL | 2025-02-26T04:12:51.422003+00:00 | 2025-02-26T04:12:51.422003+00:00 | 5 | false | # Code
```csharp []
public class Solution {
public long MaximumValueSum(int[] nums, int k, int[][] edges)
{
long[][] memo = new long[nums.Length][];
for (int i = 0; i < nums.Length; i++)
{
memo[i] = new long[] {-1, -1, -1};
// Array.Fill(memo[i], -1);
}
... | 1 | 0 | ['C#'] | 0 |
find-the-maximum-sum-of-node-values | Easiest c++ solution (Beats 100% users) | easiest-c-solution-beats-100-users-by-co-h0yu | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | cookie_33 | NORMAL | 2024-05-20T06:07:12.543773+00:00 | 2024-05-20T06:32:06.732386+00:00 | 10 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: O(N)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $... | 1 | 0 | ['Greedy', 'C++'] | 0 |
find-the-maximum-sum-of-node-values | Racket Solution | racket-solution-by-nerasnow-i0yt | Code\nracket\n(define (vector-sum vec count)\n (for/sum ([i vec][j (in-range count)]) i))\n\n(define/contract (maximum-value-sum nums k edges)\n (-> (listof | nerasnow | NORMAL | 2024-05-19T20:28:34.425279+00:00 | 2024-05-19T20:28:34.425304+00:00 | 4 | false | # Code\n```racket\n(define (vector-sum vec count)\n (for/sum ([i vec][j (in-range count)]) i))\n\n(define/contract (maximum-value-sum nums k edges)\n (-> (listof exact-integer?) exact-integer? (listof (listof exact-integer?)) exact-integer?)\n (define change (vector-sort (list->vector (map (\u03BB (i) (- (bitwis... | 1 | 0 | ['Racket'] | 1 |
find-the-maximum-sum-of-node-values | ✅All 4 approach explained || Detailed explanation ever available on internet || Must watch Sol✨ | all-4-approach-explained-detailed-explan-atx2 | \n# Overview\n\nWe aim to maximize the sum of values of all nodes in an undirected tree by performing a specific operation. \nThe operation allows us to replac | prakhar_arya | NORMAL | 2024-05-19T19:33:11.846443+00:00 | 2024-05-19T19:33:11.846471+00:00 | 22 | false | \n# Overview\n\nWe aim to maximize the sum of values of all nodes in an undirected tree by performing a specific operation. \nThe operation allows us to replace the values of any two **adjacent** nodes with their XOR values, with a given integer `k`.\n\n**Key Observations:**\n\n1. Alice can perform an operation on any... | 1 | 0 | ['Python', 'C++', 'Java', 'Python3'] | 0 |
find-the-maximum-sum-of-node-values | C++ Easy Solution | c-easy-solution-by-skill_improve-u6ol | Intuition\n Describe your first thoughts on how to solve this problem. \n\nJust calculate the xor of elements and check store the max of both element or xor of | skill_improve | NORMAL | 2024-05-19T18:59:13.359601+00:00 | 2024-05-19T18:59:13.359642+00:00 | 17 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\nJust calculate the xor of elements and check store the max of both element or xor of it with k ....and check how many of the elements get the xor greater than the element ..if the count of element xored with k are odd then we can\'t pai... | 1 | 0 | ['Array', 'Dynamic Programming', 'Greedy', 'Bit Manipulation', 'Tree', 'Sorting', 'C++'] | 0 |
find-the-maximum-sum-of-node-values | 100% beats, C, O(n), Gready, one additional variable to find best change to sacrifize. | 100-beats-c-on-gready-one-additional-var-zhdd | Intuition\nWe actually can change any pair of nodes. Let\'s find the best value (xored or not) for all nodes, then sum them up. If the number of changed values | stivsh | NORMAL | 2024-05-19T18:35:39.604418+00:00 | 2024-05-19T18:55:09.181191+00:00 | 12 | false | # Intuition\nWe actually can change any pair of nodes. Let\'s find the best value (xored or not) for all nodes, then sum them up. If the number of changed values is odd (indicating we have a redundant change), we will sacrifice the smallest non-optimal change.\n\n\n# Code\n```\nlong long maximumValueSum(int* nums, int ... | 1 | 0 | ['C'] | 0 |
find-the-maximum-sum-of-node-values | # Optimizing Array Values with Bitwise XOR | optimizing-array-values-with-bitwise-xor-f4kh | \n## Intuition\nWhen I first looked at this problem, my goal was to maximize the sum of the array after performing a bitwise XOR operation on its elements with | kazakie96 | NORMAL | 2024-05-19T18:14:33.669355+00:00 | 2024-05-19T18:14:33.669391+00:00 | 10 | false | \n## Intuition\nWhen I first looked at this problem, my goal was to maximize the sum of the array after performing a bitwise XOR operation on its elements with a given integer `k`. The key observation is that the XOR operation can sometimes increase the value of a number and sometimes decrease it. Therefore, we need to... | 1 | 0 | ['Java'] | 0 |
find-the-maximum-sum-of-node-values | C# Solution for Find the Maximum Sum of Node Values Problem | c-solution-for-find-the-maximum-sum-of-n-dq45 | Intuition\n Describe your first thoughts on how to solve this problem. \nThe key intuition behind this solution is to leverage dynamic programming to maximize t | Aman_Raj_Sinha | NORMAL | 2024-05-19T17:36:21.721535+00:00 | 2024-05-19T17:36:21.721561+00:00 | 45 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe key intuition behind this solution is to leverage dynamic programming to maximize the sum of node values after potentially performing XOR operations on the tree edges. We use a 2D dynamic programming array (dp) to track the maximum su... | 1 | 0 | ['C#'] | 0 |
find-the-maximum-sum-of-node-values | C++ || Thinking Process And Explanation | c-thinking-process-and-explanation-by-br-8sul | Intuition\n1. Consider the property of the xor operation, where any number do xor twice remains unchanged, so considering how can we apply this property to get | brm | NORMAL | 2024-05-19T17:34:19.734886+00:00 | 2024-05-20T02:38:04.263022+00:00 | 29 | false | # Intuition\n1. Consider the property of the `xor` operation, where any number do `xor` twice remains unchanged, so considering how can we apply this property to get the result.\n2. Given the `edges`, we can perform the `xor` operation on two adjacent nodes. However, it seems not using the property, we think beyond adj... | 1 | 0 | ['C++'] | 0 |
find-the-maximum-sum-of-node-values | Java Solution for Find the Maximum Sum of Node Values Problem | java-solution-for-find-the-maximum-sum-o-n7gz | Intuition\n Describe your first thoughts on how to solve this problem. \nThe key idea is to maximize the sum of node values by strategically deciding whether to | Aman_Raj_Sinha | NORMAL | 2024-05-19T17:32:00.370768+00:00 | 2024-05-19T17:32:00.370801+00:00 | 35 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe key idea is to maximize the sum of node values by strategically deciding whether to perform XOR operations on connected nodes. In a linear structure (like an array), this would involve deciding for each element whether to XOR it with ... | 1 | 0 | ['Java'] | 0 |
find-the-maximum-sum-of-node-values | Simple python3 solution | DFS + Greedy | simple-python3-solution-dfs-greedy-by-ti-adt1 | Complexity\n- Time complexity: O(n)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(n)\n Add your space complexity here, e.g. O(n) \n\n# Co | tigprog | NORMAL | 2024-05-19T17:28:36.975213+00:00 | 2024-05-19T17:29:10.878863+00:00 | 33 | false | # Complexity\n- Time complexity: $$O(n)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(n)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n``` python3 []\nclass Solution:\n def maximumValueSum(self, nums: List[int], k: int, edges: List[List[int]]) -> int:\n ... | 1 | 0 | ['Greedy', 'Depth-First Search', 'Recursion', 'Binary Tree', 'Python3'] | 1 |
find-the-maximum-sum-of-node-values | Easy JAVA Solution using Greedy Approach with intuition beats 100% | easy-java-solution-using-greedy-approach-jnmn | Intuition\n Describe your first thoughts on how to solve this problem. \nKey Observations:-\n- xor only those node\'s value with k which gives a result>node val | aRko_ | NORMAL | 2024-05-19T17:18:17.631512+00:00 | 2024-05-19T17:18:17.631564+00:00 | 32 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nKey Observations:-\n- xor only those node\'s value with k which gives a result>node val(nums[i]^k>nums[i])\n- we can choose any pair of nodes and xor them beacuase all are connected(indirectly & no. of edges=n-1).\n- we need to count for ... | 1 | 0 | ['Greedy', 'Tree', 'Graph', 'Java'] | 0 |
find-the-maximum-sum-of-node-values | Find the Maximum Sum of Node Values | find-the-maximum-sum-of-node-values-by-k-bjxy | Intuition\n Describe your first thoughts on how to solve this problem. \nTo solve the problem of finding the maximum sum of values in the nums array after perfo | kalpanahepzi_2k2 | NORMAL | 2024-05-19T15:29:38.541692+00:00 | 2024-05-19T15:29:38.541719+00:00 | 13 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nTo solve the problem of finding the maximum sum of values in the nums array after performing at most one XOR operation per element with a given integer k, we can break down the solution into a few key steps:\n1. XOR Operation: Understand ... | 1 | 0 | ['Array', 'Dynamic Programming', 'Greedy', 'Bit Manipulation', 'Tree', 'Sorting'] | 0 |
find-the-maximum-sum-of-node-values | Just practice | just-practice-by-rshakthi443-0niq | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | rshakthi443 | NORMAL | 2024-05-19T15:25:52.176213+00:00 | 2024-05-19T15:25:52.176232+00:00 | 10 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 1 | 0 | ['Python'] | 0 |
find-the-maximum-sum-of-node-values | Python3 Solution | python3-solution-by-motaharozzaman1996-83cw | \n\nclass Solution:\n def maximumValueSum(self, nums: List[int], k: int, edges: List[List[int]]) -> int:\n ans=0\n c=0\n d=1<<30\n | Motaharozzaman1996 | NORMAL | 2024-05-19T14:25:30.403903+00:00 | 2024-05-19T14:25:30.403936+00:00 | 22 | false | \n```\nclass Solution:\n def maximumValueSum(self, nums: List[int], k: int, edges: List[List[int]]) -> int:\n ans=0\n c=0\n d=1<<30\n for num in nums:\n ans+=max(num, num1:=num^k)\n c^=num<num1\n d=min(d,abs(num-num1))\n return ans-d*c \n``` | 1 | 0 | ['Python', 'Python3'] | 0 |
find-the-maximum-sum-of-node-values | Simple Solution | simple-solution-by-varunsh5687-t9t0 | Intuition\n Describe your first thoughts on how to solve this problem. \nThe intuition behind this approach is that XOR operations on elements in the list can e | varunsh5687 | NORMAL | 2024-05-19T10:41:46.249929+00:00 | 2024-05-19T10:41:46.249964+00:00 | 17 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe intuition behind this approach is that XOR operations on elements in the list can either increase or decrease their values. The goal is to maximize the overall sum after these operations. By tracking the minimum positive change and th... | 1 | 0 | ['JavaScript'] | 0 |
find-the-maximum-sum-of-node-values | Python solution with n in time and 1 in space | python-solution-with-n-in-time-and-1-in-frbd2 | Complexity\n- Time complexity:\nO(n) \n\n- Space complexity:\nO(1)\n\n# Code\n\nclass Solution:\n def maximumValueSum(self, nums, k, edges):\n maxSum = sum( | Rimkomatic | NORMAL | 2024-05-19T10:26:35.223000+00:00 | 2024-05-19T10:26:35.223025+00:00 | 8 | false | # Complexity\n- Time complexity:\n$$O(n)$$ \n\n- Space complexity:\n$$O(1)$$\n\n# Code\n```\nclass Solution:\n def maximumValueSum(self, nums, k, edges):\n maxSum = sum(max(num, num ^ k) for num in nums)\n changedCount = sum((num ^ k) > num for num in nums)\n if changedCount % 2 == 0:\n return maxSum\n ... | 1 | 0 | ['Python'] | 0 |
find-the-maximum-sum-of-node-values | 💯🔥✅ Simple JS/TS solution | simple-jsts-solution-by-serge15-jnxf | \n\n# Code\n\nfunction maximumValueSum(nums: number[], k: number, edges: number[][]): number {\n const delta = nums.map((n) => (n ^ k) - n).sort((a, b) => b | zavacode | NORMAL | 2024-05-19T10:22:17.041183+00:00 | 2024-05-19T10:22:17.041219+00:00 | 35 | false | \n\n# Code\n```\nfunction maximumValueSum(nums: number[], k: number, edges: number[][]): number {\n const delta = nums.map((n) => (n ^ k) - n).sort((a, b) => b - a)\n\tlet res = nums.reduce((acc, curr) => acc + curr, 0)\n\n\tfor (let i = 0; i < nums.length; i += 2) {\n\t\tif (i === nums.length - 1) break\n\t\t\n ... | 1 | 0 | ['Array', 'Greedy', 'Bit Manipulation', 'Tree', 'Sorting', 'TypeScript', 'JavaScript'] | 0 |
find-the-maximum-sum-of-node-values | Find the Maximum Sum of Node Values | find-the-maximum-sum-of-node-values-by-a-gacn | Intuition\n \n# Approach\n\n# Complexity\n- Time complexity:\n\n- Space complexity:\n\n\n# Code\n\nclass Solution {\npublic:\n long long maximumValueSum(vect | Ayushivts | NORMAL | 2024-05-19T10:07:10.969276+00:00 | 2024-05-19T10:07:10.969299+00:00 | 2 | false | # Intuition\n \n# Approach\n\n# Complexity\n- Time complexity:\n\n- Space complexity:\n\n\n# Code\n```\nclass Solution {\npublic:\n long long maximumValueSum(vector<int>& nums, int k, vector<vector<int>>& edges) {\n long long totalSum = 0;\n int count = 0;\n int positiveMin = INT_MAX;\n i... | 1 | 0 | ['C++'] | 0 |
find-the-maximum-sum-of-node-values | Python easy and best O(N) solution | python-easy-and-best-on-solution-by-mas5-m95k | Intuition\n Describe your first thoughts on how to solve this problem. \nplaying with maximum and minimum\n# Approach\n Describe your approach to solving the pr | MAS5236 | NORMAL | 2024-05-19T09:42:30.816478+00:00 | 2024-05-19T09:42:30.816507+00:00 | 7 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nplaying with maximum and minimum\n# Approach\n<!-- Describe your approach to solving the problem. -->\niterating\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(N)\n- Space complexity:\n<!-- Add... | 1 | 0 | ['Python3'] | 0 |
find-the-maximum-sum-of-node-values | C# Simple - THE QUESTION IS MISLEADING, first i got confused we can choose only nodes from edges | c-simple-the-question-is-misleading-firs-m2zm | Seems we can select any pair of nodes\n\n# Code\n\npublic class Solution {\n public long MaximumValueSum(int[] nums, int k, int[][] edges) {\n int len | expected_error | NORMAL | 2024-05-19T08:58:29.359154+00:00 | 2024-05-19T08:58:29.359181+00:00 | 11 | false | Seems we can select any pair of nodes\n\n# Code\n```\npublic class Solution {\n public long MaximumValueSum(int[] nums, int k, int[][] edges) {\n int len=nums.Length;\n int[] delta=new int[len];\n long sum=0;\n for(int i=0;i<len;i++)\n {\n delta[i]=(nums[i]^k)-nums[i];\n... | 1 | 0 | ['C#'] | 0 |
find-the-maximum-sum-of-node-values | EASIEST PYTHON3 CODE!!! | easiest-python3-code-by-amanshukla07-fhid | Intuition\n Describe your first thoughts on how to solve this problem. \nThe operation Alice performs essentially flips the bits of nums[u] and nums[v] at corre | AmanShukla07 | NORMAL | 2024-05-19T08:56:34.834475+00:00 | 2024-05-19T08:56:34.834503+00:00 | 4 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe operation Alice performs essentially flips the bits of nums[u] and nums[v] at corresponding positions using the XOR (^) operator. This operation has some key properties that help us find the maximum sum:\n\nXOR with itself is zero: a ... | 1 | 0 | ['Python3'] | 0 |
find-the-maximum-sum-of-node-values | Scala FP: sorting (actually even unnecessary), not using edges | scala-fp-sorting-actually-even-unnecessa-v7d9 | Code\n\nobject Solution {\n def maximumValueSum(nums: Array[Int], k: Int, edges: Array[Array[Int]]): Long = {\n val nProfit = nums.map(n => n -> ((n ^ k) - | SerhiyShaman | NORMAL | 2024-05-19T08:39:20.190437+00:00 | 2024-05-19T08:39:20.190474+00:00 | 8 | false | # Code\n```\nobject Solution {\n def maximumValueSum(nums: Array[Int], k: Int, edges: Array[Array[Int]]): Long = {\n val nProfit = nums.map(n => n -> ((n ^ k) - n)).sortBy(-_._2)\n val evenCount = nProfit.count(_._2 > 0) / 2 * 2\n val xorCount = if (evenCount + 2 <= nums.length && nProfit(evenCount)._2 + nPro... | 1 | 0 | ['Scala'] | 0 |
find-the-maximum-sum-of-node-values | cpp solution | cpp-solution-by-sinchanar2000-lsot | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | sinchanar2000 | NORMAL | 2024-05-19T08:30:38.800023+00:00 | 2024-05-19T08:30:38.800052+00:00 | 29 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 1 | 0 | ['C++'] | 0 |
find-the-maximum-sum-of-node-values | EASY PYTHON SOLUTION || | easy-python-solution-by-gagansharmadev-am9q | TIME COMPLEXITY - O(nlogn)\nSPACE COMPLEXITY - O(n)\n\nPERFORMING THE XOR OPERATION ON ANY 2 NODES AND FINDING DELTA THE DIFFERENCE BETWEEN ORIGINAL AND NEW NOD | gagansharmadev | NORMAL | 2024-05-19T07:51:17.332056+00:00 | 2024-05-19T07:51:17.332088+00:00 | 30 | false | TIME COMPLEXITY - O(nlogn)\nSPACE COMPLEXITY - O(n)\n\nPERFORMING THE XOR OPERATION ON ANY 2 NODES AND FINDING DELTA THE DIFFERENCE BETWEEN ORIGINAL AND NEW NODE VALUES .\nIF THE DIFFERENCE IS POSITIVE WE ADD IT TO THE TOTAL DEALTA OTHERWISE BREAK IT .\n\n# Code PYTHON\n```\nclass Solution:\n def maximumValueSum(sel... | 1 | 0 | ['Python3'] | 0 |
find-the-maximum-sum-of-node-values | Can XOR any two nodes | can-xor-any-two-nodes-by-shynggys-asnx | Intuition\nCan XOR any two nodes\n\n# Approach\nXOR elements in the path = XOR only first and last element in the path. So we don\'t even need edges, and we can | shynggys | NORMAL | 2024-05-19T07:32:39.091743+00:00 | 2024-05-19T07:32:39.091780+00:00 | 8 | false | # Intuition\nCan XOR any two nodes\n\n# Approach\nXOR elements in the path = XOR only first and last element in the path. So we don\'t even need edges, and we can XOR any two nodes in the tree. \n\n\n# Complexity\n- Time complexity: O(n * log(n)), n = number of nodes\n\n- Space complexity: O(n) -> storing XOR values\n\... | 1 | 0 | ['Python3'] | 1 |
find-the-maximum-sum-of-node-values | Edges Not Required || Greedy Maximise XOR || C++ | edges-not-required-greedy-maximise-xor-c-qmuh | Intuition\n Describe your first thoughts on how to solve this problem. \nAs we can join whichever edges we like, the edges given are not required, as we can jus | traveler1 | NORMAL | 2024-05-19T06:44:51.292346+00:00 | 2024-05-19T06:44:51.292373+00:00 | 86 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nAs we can join whichever edges we like, the edges given are not required, as we can just greedily choose the best values to increase the overall sum.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. The min value... | 1 | 0 | ['Greedy', 'C++'] | 2 |
find-the-maximum-sum-of-node-values | 🔥✅ | 99.78% beats ✅ | ✅ Easy Code | ✅🔥 | 9978-beats-easy-code-by-b_i_t-7cwc | \n# Intuition and Approach\nThe goal of this solution is to maximize the sum of values of nodes in a tree after possibly performing XOR operations with a given | B_I_T | NORMAL | 2024-05-19T06:06:38.810759+00:00 | 2024-05-19T06:07:39.075616+00:00 | 33 | false | \n# Intuition and Approach\nThe goal of this solution is to maximize the sum of values of nodes in a tree after possibly performing XOR operations with a given integer k on the... | 1 | 0 | ['Array', 'Greedy', 'Bit Manipulation', 'Tree', 'Python', 'C++', 'Java', 'JavaScript'] | 0 |
find-the-maximum-sum-of-node-values | [Kotlin] Easy solution, time O(n), space O(1) | kotlin-easy-solution-time-on-space-o1-by-otno | Approach\n- Step 1: For any two non-adjacent nodes U and V in the tree we can replace their values with the XOR values\n- Step 2: If the number of netChange is | namanh11611 | NORMAL | 2024-05-19T05:33:12.246861+00:00 | 2024-05-19T05:33:12.246881+00:00 | 8 | false | # Approach\n- Step 1: For any two non-adjacent nodes U and V in the tree we can replace their values with the XOR values\n- Step 2: If the number of netChange is positive is even, we can return current sum\n- Step 3: If the number of netChange is positive is odd, we have to reduce minChange\n\n# Complexity\n- Time comp... | 1 | 0 | ['Kotlin'] | 1 |
find-the-maximum-sum-of-node-values | Faster⏰||Simpler🧠||Efficient✅ | fastersimplerefficient-by-rexton_george_-05ax | \n# Code\npython3 []\nclass Solution:\n def maximumValueSum(self, nums: List[int], k: int, edges: List[List[int]]) -> int:\n totalSum = 0\n cou | Rexton_George_R | NORMAL | 2024-05-19T05:17:46.808850+00:00 | 2024-05-19T05:17:46.808898+00:00 | 109 | false | \n# Code\n```python3 []\nclass Solution:\n def maximumValueSum(self, nums: List[int], k: int, edges: List[List[int]]) -> int:\n totalSum = 0\n count = 0\n positiveMin = float("inf")\n negativeMax = float("-inf")\n\n for nodeValue in nums:\n nodeValAfterOperation = nodeVa... | 1 | 0 | ['C++', 'Java', 'Python3', 'JavaScript'] | 1 |
find-the-maximum-sum-of-node-values | ✅ [Beats 100%] Swift. Accepted solution | beats-100-swift-accepted-solution-by-pro-s53o | \n\n# Complexity\n- Time complexity:\nO(nlogn)\n\n- Space complexity:\nO(n)\n\n# Code\n\nclass Solution {\n func maximumValueSum(_ nums: [Int], _ k: Int, _ e | protodimbo | NORMAL | 2024-05-19T05:09:58.898121+00:00 | 2024-05-19T05:09:58.898139+00:00 | 21 | false | \n\n# Complexity\n- Time complexity:\n$$O(nlogn)$$\n\n- Space complexity:\n$$O(n)$$\n\n# Code\n```\nclass Solution {\n func maximumValueSum(_ nums: [Int], _ k: Int, _ edges:... | 1 | 0 | ['Swift'] | 0 |
find-the-maximum-sum-of-node-values | Can Somebody find Error in Above Code | can-somebody-find-error-in-above-code-by-19zg | Code\n\n// class Solution {\n// public long maximumValueSum(int[] nums, int k, int[][] edges) {\n// int n = nums.length;\n// int[] vis = new | Shree_Govind_Jee | NORMAL | 2024-05-19T04:12:10.351586+00:00 | 2024-05-19T04:12:10.351612+00:00 | 70 | false | # Code\n```\n// class Solution {\n// public long maximumValueSum(int[] nums, int k, int[][] edges) {\n// int n = nums.length;\n// int[] vis = new int[n];\n// for (int i = 0; i < n - 1; i++) {\n// vis[edges[i][0]] = edges[i][0];\n// vis[edges[i][0]] = edges[i][0];\n// ... | 1 | 0 | ['Array', 'Dynamic Programming', 'Greedy', 'Bit Manipulation', 'Tree', 'Java'] | 1 |
find-the-maximum-sum-of-node-values | ✅✅understandable solution in java | understandable-solution-in-java-by-manto-d5gn | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | mantosh_kumar04 | NORMAL | 2024-05-19T04:00:44.195781+00:00 | 2024-05-19T04:00:44.195812+00:00 | 6 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 1 | 0 | ['Java'] | 0 |
find-the-maximum-sum-of-node-values | python, ruby 1-liners | python-ruby-1-liners-by-_-k-03k1 | ruby\n\ndef maximum_value_sum(a, k, edges) =\n\n a.sum{ [k^_1,_1].max } - a.count{ k^_1>_1 }%2 * a.map{ (_1.-_1^k).abs }.min\n\n\npython\n\nclass Solution:\n | _-k- | NORMAL | 2024-05-19T03:49:04.623162+00:00 | 2024-05-19T05:03:01.534712+00:00 | 52 | false | ruby\n```\ndef maximum_value_sum(a, k, edges) =\n\n a.sum{ [k^_1,_1].max } - a.count{ k^_1>_1 }%2 * a.map{ (_1.-_1^k).abs }.min\n```\n\npython\n```\nclass Solution:\n def maximumValueSum(self, a, k, edges):\n\n return sum( max(x,x^k) for x in a ) - sum( x^k>x for x in a )%2 * min( abs(x-(x^k)) for x in a )\n``` | 1 | 0 | ['Python', 'Python3', 'Ruby'] | 1 |
find-the-maximum-sum-of-node-values | ✅ Easy C++ Solution | easy-c-solution-by-moheat-5m6q | Code\n\nclass Solution {\npublic:\n long long maximumValueSum(vector<int>& v, int k, vector<vector<int>>& edges) {\n long long total = accumulate(v.be | moheat | NORMAL | 2024-05-19T03:47:32.775376+00:00 | 2024-05-19T03:47:32.775400+00:00 | 198 | false | # Code\n```\nclass Solution {\npublic:\n long long maximumValueSum(vector<int>& v, int k, vector<vector<int>>& edges) {\n long long total = accumulate(v.begin(), v.end(), 0ll);\n \n long long totalDiff = 0;\n long long diff;\n int positiveCount = 0;\n long long minDiff = num... | 1 | 0 | ['C++'] | 1 |
find-the-maximum-sum-of-node-values | Simple C Solution | simple-c-solution-by-anshadk-v50j | Complexity\n- Time complexity: O(n)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(n)\n Add your space complexity here, e.g. O(n) \n\n# Co | anshadk | NORMAL | 2024-05-19T03:10:52.645994+00:00 | 2024-05-19T03:10:52.646016+00:00 | 32 | false | # Complexity\n- Time complexity: $$O(n)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(n)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\ntypedef struct {\n long long first;\n long long second;\n} pair;\n\nlong long maximumValueSum(int* nums, int n, i... | 1 | 0 | ['C'] | 0 |
find-the-maximum-sum-of-node-values | Pick (or) Not-Pick || Damn Easy Solution | pick-or-not-pick-damn-easy-solution-by-j-kj96 | Approach\n\n- DFS\n- flag_index is the state of the current node.\n- If the current_index is picked then the flag_index is flipped to indicate the change of sta | Jagadish_Shankar | NORMAL | 2024-05-19T02:43:03.382869+00:00 | 2024-05-19T02:43:55.128237+00:00 | 131 | false | # Approach\n\n- DFS\n- ```flag_index``` is the state of the current node.\n- If the ```current_index``` is picked then the ```flag_index``` is flipped to indicate the change of state of the node.\n\n# Complexity\n\n- Time complexity : $$O(N)$$\n\n- Space complexity : $$O(H)$$\n\n# Code\n\n```\nclass Solution {\n\n p... | 1 | 0 | ['Dynamic Programming', 'Depth-First Search', 'Recursion', 'Memoization', 'Java'] | 1 |
find-the-maximum-sum-of-node-values | rust simplest solution with explain | rust-simplest-solution-with-explain-by-s-zf44 | Intuition\nWhy I need edges? If you want to flip a and b, you can always find a path from a to b, and file all the path twice.\n\nSo you can filp as many time y | sovlynn | NORMAL | 2024-05-19T02:21:43.481069+00:00 | 2024-05-19T02:21:43.481121+00:00 | 82 | false | # Intuition\nWhy I need edges? If you want to flip a and b, you can always find a path from a to b, and file all the path twice.\n\nSo you can filp as many time you want, just make sure the total flip time is even.\n\n# Complexity\n- Time complexity:\n$$O(n)$$\n\n- Space complexity:\n$$O(1)$$\n\n# Code\n```\nimpl Solut... | 1 | 0 | ['Rust'] | 0 |
find-the-maximum-sum-of-node-values | JS | Clean Code (RunTime Beats 100% | Memory Beats 100%) | js-clean-code-runtime-beats-100-memory-b-f5xj | \n\n# Code\n\n/**\n * @param {number[]} nums\n * @param {number} k\n * @param {number[][]} edges\n * @return {number}\n */\nvar maximumValueSum = function (nums | nanlyn | NORMAL | 2024-05-19T01:48:12.484104+00:00 | 2024-05-19T01:48:12.484170+00:00 | 21 | false | \n\n# Code\n```\n/**\n * @param {number[]} nums\n * @param {number} k\n * @param {number[][]} edges\n * @return {number}\n */\nvar maximumValueSum = function (nums, k, edges) {\n... | 1 | 0 | ['JavaScript'] | 0 |
find-the-maximum-sum-of-node-values | 🔥 Go Beat 100% || O(n) / O(1) || With explanation 🔥 | go-beat-100-on-o1-with-explanation-by-co-tiev | Intuition\n1. XORing a number twice with k leaves it unchanged.\uFF08a XOR k XOR k = a\uFF09\n2. For a path from node a to node b in a tree, if each edge on the | ConstantineJin | NORMAL | 2024-05-19T01:43:11.172831+00:00 | 2024-05-19T01:43:11.172859+00:00 | 30 | false | # Intuition\n1. XORing a number twice with `k` leaves it unchanged.\uFF08a XOR k XOR k = a\uFF09\n2. For a path from node `a` to node `b` in a tree, if each edge on the path is XORed, then all nodes on the path except `a` and `b` undergo an even number of XOR operations, keeping their values unchanged. Hence, the probl... | 1 | 0 | ['Dynamic Programming', 'Go'] | 0 |
find-the-maximum-sum-of-node-values | Fastest Solution | fastest-solution-by-deleted_user-dhan | Code\n\n// sample 116 ms submission\nstatic auto speedup = []() { std::ios_base::sync_with_stdio(false); std::cout.tie(nullptr); std::cin.tie(nullptr); return N | deleted_user | NORMAL | 2024-05-19T01:35:27.149139+00:00 | 2024-05-19T01:35:27.149156+00:00 | 17 | false | # Code\n```\n// sample 116 ms submission\nstatic auto speedup = []() { std::ios_base::sync_with_stdio(false); std::cout.tie(nullptr); std::cin.tie(nullptr); return NULL; }();\nclass Solution\n{\npublic:\n long long maximumValueSum(vector<int> &nums, int k, vector<vector<int>> &edges)\n {\n long long cnt = ... | 1 | 0 | ['C++'] | 0 |
find-the-maximum-sum-of-node-values | 💯Beats💯Python✅Java✅C++✅Step-By-Step🔥Clean code w/ Explanation⚡️ | beatspythonjavacstep-by-stepclean-code-w-u534 | Step 1: Possibilities For Each Node \uD83D\uDE2E\n\n- Each node can either be nums[i] or nums[i]^k\n- This is because nums[i]^k^k = nums[i] \uD83D\uDCDD\n\n# St | CutSandstone | NORMAL | 2024-05-19T01:31:24.876260+00:00 | 2024-05-19T01:31:24.876286+00:00 | 15 | false | # Step 1: Possibilities For Each Node \uD83D\uDE2E\n\n- Each node can either be ```nums[i]``` or ```nums[i]^k```\n- This is because ```nums[i]^k^k = nums[i]``` \uD83D\uDCDD\n\n# Step 2: Removing The Tree \uD83C\uDF32\n\n- By definition of a tree, there exists a path \uD83C\uDFDE between any 2 nodes\n- If we apply the o... | 1 | 0 | ['Bit Manipulation', 'C++', 'Java', 'Python3'] | 0 |
find-the-maximum-sum-of-node-values | scala solution | scala-solution-by-lyk4411-2oid | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | lyk4411 | NORMAL | 2024-05-19T01:06:43.149418+00:00 | 2024-05-19T01:06:43.149446+00:00 | 20 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 1 | 0 | ['Scala'] | 0 |
find-the-maximum-sum-of-node-values | Count Number of Changed Nodes || C++, C, Python, Java | count-number-of-changed-nodes-c-c-python-fzjh | Approach\n Describe your approach to solving the problem. \nSince the graph we\'re given is connected, undirected and acyclic, there is a path between any two n | not_yl3 | NORMAL | 2024-05-19T00:37:02.932890+00:00 | 2024-05-19T02:25:42.826096+00:00 | 222 | false | # Approach\n<!-- Describe your approach to solving the problem. -->\nSince the graph we\'re given is connected, undirected and acyclic, there is a path between any two nodes in the graph. Moreover, because of the properties of the XOR operation, any nodes in the path between node `u` and node `v` will remain the same s... | 1 | 0 | ['Array', 'Dynamic Programming', 'Greedy', 'Tree', 'C', 'Sorting', 'Python', 'C++', 'Java', 'Python3'] | 1 |
find-the-maximum-sum-of-node-values | Java Solution NO DFS | java-solution-no-dfs-by-shaurya_malhan-zwm4 | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time | Shaurya_Malhan | NORMAL | 2024-03-07T06:56:19.193713+00:00 | 2024-03-07T06:56:19.193745+00:00 | 75 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 1 | 0 | ['Java'] | 1 |
find-the-maximum-sum-of-node-values | Just a runnable solution | just-a-runnable-solution-by-ssrlive-7p5f | \n\nimpl Solution {\n pub fn maximum_value_sum(nums: Vec<i32>, k: i32, _edges: Vec<Vec<i32>>) -> i64 {\n let nums: Vec<i64> = nums.iter().map(|&x| x a | ssrlive | NORMAL | 2024-03-05T10:20:39.471518+00:00 | 2024-05-20T00:53:46.842548+00:00 | 51 | false | \n```\nimpl Solution {\n pub fn maximum_value_sum(nums: Vec<i32>, k: i32, _edges: Vec<Vec<i32>>) -> i64 {\n let nums: Vec<i64> = nums.iter().map(|&x| x as i64).collect();\n let k = k as i64;\n let mut sum = 0;\n let mut cnt = 0;\n let mut sacrifice = i64::MAX;\n for &n in nu... | 1 | 0 | ['Rust'] | 1 |
find-the-maximum-sum-of-node-values | Best c++ solution || Beats 100%🎯 | best-c-solution-beats-100-by-lovy4200-v1nf | Intuition\n Describe your first thoughts on how to solve this problem. XORing an even number of times by the same element results in the original number. \na ^ | lovy4200 | NORMAL | 2024-03-04T05:51:51.004219+00:00 | 2024-03-04T09:18:45.103416+00:00 | 104 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->XORing an even number of times by the same element results in the original number. \na ^ b ^ b = a --> The important property of XOR.\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. For each element in the given ar... | 1 | 0 | ['C++'] | 3 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.