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
minimum-number-of-moves-to-make-palindrome
TypeScript Greedy faster that 100%
typescript-greedy-faster-that-100-by-kam-s2yt
\nfunction minMovesToMakePalindrome(s: string): number {\n let leftIndex = 0\n let rightIndex = s.length - 1\n const sArr: string[] = Array.from(s)\n
kamrankoupayi
NORMAL
2022-04-02T14:38:52.972330+00:00
2022-04-02T14:38:52.972369+00:00
187
false
```\nfunction minMovesToMakePalindrome(s: string): number {\n let leftIndex = 0\n let rightIndex = s.length - 1\n const sArr: string[] = Array.from(s)\n let sumChange = 0\n \n while(leftIndex < rightIndex){\n if(sArr[leftIndex] === sArr[rightIndex]){\n leftIndex ++\n right...
1
0
[]
0
minimum-number-of-moves-to-make-palindrome
C++ Greedy Solution O(N ^ 2)
c-greedy-solution-on-2-by-ahsan83-02eg
Runtime: 31 ms, faster than 47.44% of C++ online submissions for Minimum Number of Moves to Make Palindrome.\nMemory Usage: 6.8 MB, less than 50.32% of C++ onli
ahsan83
NORMAL
2022-03-15T04:53:30.891664+00:00
2022-03-15T04:54:45.318316+00:00
366
false
Runtime: 31 ms, faster than 47.44% of C++ online submissions for Minimum Number of Moves to Make Palindrome.\nMemory Usage: 6.8 MB, less than 50.32% of C++ online submissions for Minimum Number of Moves to Make Palindrome.\n\n```\nTo make string palindrome we can keep left half of string in exact position and change \n...
1
0
['Two Pointers', 'Greedy', 'C']
0
minimum-number-of-moves-to-make-palindrome
[Java] greedy with explanation
java-greedy-with-explanation-by-jaylenzh-frpq
Each time we check the first and the last character. If they are the same, we can quickly shrink this problem into a subproblem with the size of n - 2. \nIf the
jaylenzhang19
NORMAL
2022-03-09T02:42:33.821624+00:00
2022-03-09T02:51:43.720210+00:00
396
false
Each time we check the first and the last character. If they are the same, we can quickly shrink this problem into a subproblem with the size of n - 2. \nIf they are not the same, such as "a..b..a..b", then the answer becomes which character we need to choose as the end of both sides. If we choose \'a\', we need to mov...
1
0
[]
0
minimum-number-of-moves-to-make-palindrome
C# Solution without swapping, uses maths
c-solution-without-swapping-uses-maths-b-pw8r
\npublic class Solution {\n public int MinMovesToMakePalindrome (string s) {\n int sum = 0;\n List<char> chars = s.ToCharArray ().ToList ();\n
10f
NORMAL
2022-03-08T23:36:07.047032+00:00
2022-03-08T23:36:07.047076+00:00
267
false
```\npublic class Solution {\n public int MinMovesToMakePalindrome (string s) {\n int sum = 0;\n List<char> chars = s.ToCharArray ().ToList ();\n int b = 0, e = chars.Count - 1;\n while (b < e) {\n if (chars[b] != chars[e]) {\n int maxIx = -1;\n fo...
1
0
['Math']
0
minimum-number-of-moves-to-make-palindrome
[Javascript] Two Pointer
javascript-two-pointer-by-vj98-qr24
\n/**\n * @param {string} s\n * @return {number}\n */\nvar minMovesToMakePalindrome = function(s) {\n let left = 0, right = s.length-1, ans = 0;\n \n \
vj98
NORMAL
2022-03-06T04:26:02.431726+00:00
2022-03-06T04:26:02.431773+00:00
723
false
```\n/**\n * @param {string} s\n * @return {number}\n */\nvar minMovesToMakePalindrome = function(s) {\n let left = 0, right = s.length-1, ans = 0;\n \n \n function swapStr(str, first, last){\n return str.substr(0, first)\n + str[last]\n + str.substring(first+1, last)\n ...
1
0
['Two Pointers', 'String', 'Greedy', 'JavaScript']
0
minimum-number-of-moves-to-make-palindrome
C++,Simple brute force two pointers
csimple-brute-force-two-pointers-by-fors-lqzz
```\nclass Solution {\npublic: \n int minMovesToMakePalindrome(string s) {\n int n = s.length();\n int count = 0;\n int left = 0;\n
forsakencode
NORMAL
2022-03-05T18:22:45.770145+00:00
2022-03-05T18:22:45.770195+00:00
163
false
```\nclass Solution {\npublic: \n int minMovesToMakePalindrome(string s) {\n int n = s.length();\n int count = 0;\n int left = 0;\n int right = n - 1;\n while(left < right)\n {\n int tl = right,tr = left,c1 = 0,c2 = 0;\n while(s[left]!=s[tl])\n ...
1
0
['Two Pointers', 'C']
0
minimum-number-of-moves-to-make-palindrome
Python - simple
python-simple-by-ante-krpm
Old school grinding:\n\nclass Solution:\n def minMovesToMakePalindrome(self, s: str) -> int:\n s,N = list(s), len(s)\n min_swaps = i = 0\n
Ante_
NORMAL
2022-03-05T16:30:09.160107+00:00
2022-03-05T18:40:00.434406+00:00
357
false
Old school grinding:\n```\nclass Solution:\n def minMovesToMakePalindrome(self, s: str) -> int:\n s,N = list(s), len(s)\n min_swaps = i = 0\n while i < N // 2:\n L, R = i, N - i - 1\n while L < R:\n if s[L] == s[R]: break\n else: R -= 1\n ...
1
0
[]
0
minimum-number-of-moves-to-make-palindrome
C++ Two pointers greedy algo O(N^2)
c-two-pointers-greedy-algo-on2-by-cqbaoy-3rfz
The idea is to consider two pointers, from left end and right end, to the middle.\nWhenever there is a pair of the same letters, swap the right one towards the
cqbaoyi
NORMAL
2022-03-05T16:15:03.633887+00:00
2022-03-05T16:18:44.384463+00:00
270
false
The idea is to consider two pointers, from left end and right end, to the middle.\nWhenever there is a pair of the same letters, swap the right one towards the right end till it finds the correct position.\nA special condition is that there might be a single letter on the left, which does not find its counterpart on th...
1
0
['Greedy', 'C']
0
minimum-number-of-moves-to-make-palindrome
O(n^2) solution || greedy approach || c++
on2-solution-greedy-approach-c-by-ashish-9oha
\tclass Solution {\n\tpublic:\n\n\n\t\tint minMovesToMakePalindrome(string s) {\n\t\t\tint n = s.size();\n\t\t\tint i=0;\n\t\t\tint j= n-1;\n\t\t\tint ans = 0;\
ashish_nsut
NORMAL
2022-03-05T16:12:25.259804+00:00
2022-03-05T16:13:03.030655+00:00
389
false
\tclass Solution {\n\tpublic:\n\n\n\t\tint minMovesToMakePalindrome(string s) {\n\t\t\tint n = s.size();\n\t\t\tint i=0;\n\t\t\tint j= n-1;\n\t\t\tint ans = 0;\n\t\t\twhile(i <= j){\n\t\t\t\tif(s[i] == s[j]){\n\t\t\t\t\ti++;\n\t\t\t\t\tj--;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\telse{\n\t\t\t\t\tint idx1 = -1;\n\t\t\...
1
0
[]
0
minimum-number-of-moves-to-make-palindrome
Python | Greedy Easy and Clean Solution
python-greedy-easy-and-clean-solution-by-wmj8
\nclass Solution:\n def minMovesToMakePalindrome(self, s: str) -> int:\n s = list(s)\n n = len(s)\n left, right = 0, n-1\n res =
aryonbe
NORMAL
2022-03-05T16:10:49.216312+00:00
2022-04-23T13:22:20.988632+00:00
346
false
```\nclass Solution:\n def minMovesToMakePalindrome(self, s: str) -> int:\n s = list(s)\n n = len(s)\n left, right = 0, n-1\n res = 0\n while left < right:\n if s[left] != s[right]:\n lidx, ridx = left+1, right-1\n rdelta = 1\n ...
1
0
['Greedy', 'Python']
0
minimum-number-of-moves-to-make-palindrome
Two pointers, explained
two-pointers-explained-by-sebnyberg-gkmz
Use a left pointer l and right pointer r.\n\nEach iteration we move both pointers one step inwards.\n\nIf s[l] == s[r], then continue.\n\nIf s[l] != s[r], then
sebnyberg
NORMAL
2022-03-05T16:07:37.389752+00:00
2022-03-05T16:34:10.935628+00:00
224
false
Use a left pointer `l` and right pointer `r`.\n\nEach iteration we move both pointers one step inwards.\n\nIf `s[l] == s[r]`, then continue.\n\nIf `s[l] != s[r]`, then some number of swaps must happen to bring the right character in place.\n\nHow do we know that there isn\'t some other character that is not in the firs...
1
0
['Go']
1
minimum-number-of-moves-to-make-palindrome
EXPLAINED || TWO POINTER || CPP SOLUTION
explained-two-pointer-cpp-solution-by-dd-lvuv
\n// TWO- POINTER APPROACH\n\n// 1. traversed from the two ends and chose the best possible option out of the characters which has its count left greater than
dd_07
NORMAL
2022-03-05T16:06:18.738394+00:00
2022-03-05T16:13:19.567485+00:00
323
false
```\n// TWO- POINTER APPROACH\n\n// 1. traversed from the two ends and chose the best possible option out of the characters which has its count left greater than equal to 2 \n\n// 2. calculated the no. of swaps\n\n// Please do upvote if u like my solution\n\nclass Solution {\npublic:\n #define ll int\n int minMo...
1
0
['Two Pointers', 'C++']
0
minimum-number-of-moves-to-make-palindrome
python solution
python-solution-by-lokeshrai-ig1m
\nclass Solution:\n def minMovesToMakePalindrome(self, s: str) -> int:\n s = [i for i in s]\n start = 0\n end = len(s)-1\n count
lokeshrai
NORMAL
2022-03-05T16:04:14.684758+00:00
2022-03-05T16:04:14.684786+00:00
430
false
```\nclass Solution:\n def minMovesToMakePalindrome(self, s: str) -> int:\n s = [i for i in s]\n start = 0\n end = len(s)-1\n count = 0\n while start < end:\n if s[start] != s[end]:\n i = start\n j = end\n j_f = i_f = False\n ...
1
0
['Python']
0
minimum-number-of-moves-to-make-palindrome
Intutive C++ Solution
intutive-c-solution-by-rattanankit2004-250k
Code
rattanankit2004
NORMAL
2025-03-19T14:22:33.491749+00:00
2025-03-19T14:22:33.491749+00:00
3
false
# Code ```cpp [] class Solution { public: int minMovesToMakePalindrome(string s) { int n = s.size(); int i = 0; int j =n-1; int ans = 0; while(i < j){ if(s[i] == s[j]){ i++;j--; } else{ int k = j; w...
0
0
['C++']
0
minimum-number-of-moves-to-make-palindrome
python
python-by-mykono-762k
Code
Mykono
NORMAL
2025-03-02T20:27:40.944063+00:00
2025-03-02T20:27:40.944063+00:00
9
false
# Code ```python3 [] class Solution: def minMovesToMakePalindrome(self, s): s = list(s) res = 0 while s: i = s.index(s[-1]) if i == len(s) - 1: res += i // 2 else: res += i s.pop(i) s.pop() ...
0
0
['Python3']
0
minimum-number-of-moves-to-make-palindrome
Minimum moves to make the string palindrome
minimum-moves-to-make-the-string-palindr-sfl0
IntuitionApproachComplexity Time complexity: Space complexity: Code
RODES
NORMAL
2025-03-02T10:45:20.115053+00:00
2025-03-02T10:45:20.115053+00:00
4
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code `...
0
0
['C++']
0
minimum-number-of-moves-to-make-palindrome
greedy + two pointer in c++ 🙃
greedy-two-pointer-in-c-by-yueyingyang-w0wb
Intuitioni think we need to memorize the -1 situation, which is odd_cnt >= 2.then for the two pointer, find the number that equals to the nums[i] from the right
yueyingyang
NORMAL
2025-02-24T00:56:40.528069+00:00
2025-02-24T00:56:40.528069+00:00
4
false
# Intuition i think we need to memorize the -1 situation, which is odd_cnt >= 2. then for the two pointer, find the number that equals to the nums[i] from the right, swap one by one to the left. if nums[i] is of odd count, swap to the right by 1 to leave it in the middle in the end. failed for the test case "skwhhaaun...
0
0
['C++']
0
minimum-number-of-moves-to-make-palindrome
Golang, Greedy two pointers
golang-greedy-two-pointers-by-mikyasalem-ezqy
IntuitionFocus on a single rune and attempt to swap adjacent ones until it forms a palindrome.Ex: aabb, the first a and the last b must be same, fix a and try t
mikyasalemayehu1
NORMAL
2025-02-15T18:09:02.151462+00:00
2025-02-15T18:09:02.151462+00:00
4
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> Focus on a single rune and attempt to swap adjacent ones until it forms a palindrome. Ex: **aabb**, the first **a** and the last **b** must be same, fix a and try to change the last b to a by swaping adjecents (count every swap opperation)...
0
0
['Two Pointers', 'Greedy', 'Go']
0
minimum-number-of-moves-to-make-palindrome
[python3] 2 pointers time: O(n) space: O(1)
python3-2-pointers-time-on-space-o1-by-t-3hjf
ApproachFind a matching character for s[l] from right side by searching backward. If a match is found, swap it step by step to bring it to right, counting swaps
Tianze_Kang
NORMAL
2025-02-11T01:25:51.830251+00:00
2025-02-11T01:25:51.830251+00:00
37
false
# Approach <!-- Describe your approach to solving the problem. --> Find a matching character for s[l] from right side by searching backward. If a match is found, swap it step by step to bring it to right, counting swaps. If no match is found (s[l] appears only once), move it one step right to push it toward the center....
0
0
['Python3']
0
minimum-number-of-moves-to-make-palindrome
JavaScript solution
javascript-solution-by-janhaviii-vfdc
Approach If the characters at the left and right positions match, move both pointers inward. If they don't match: Search for the closest character from the rig
janhaviii
NORMAL
2025-02-07T13:37:19.992454+00:00
2025-02-07T13:37:19.992454+00:00
11
false
# Approach 1. If the characters at the left and right positions match, move both pointers inward. 2. If they don't match: - Search for the closest character from the right side that matches the character at arr[left]. - If no match is found (i.e., arr[left] is the last occurrence), swap arr[left] with the adjac...
0
0
['Two Pointers', 'String', 'Greedy', 'JavaScript']
0
minimum-number-of-moves-to-make-palindrome
c++ easy solution
c-easy-solution-by-daniux-7g7g
IntuitionApproachComplexity Time complexity: O(n^2) Space complexity: o(n) Code
daniux
NORMAL
2025-01-28T00:25:09.015388+00:00
2025-01-28T00:25:09.015388+00:00
6
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: O(n^2) <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: o(n) <!-- Add your space complexity here, e.g. $$O(n)$$ -...
0
0
['C++']
0
minimum-number-of-moves-to-make-palindrome
2193. Minimum Number of Moves to Make Palindrome
2193-minimum-number-of-moves-to-make-pal-jtue
IntuitionApproachComplexity Time complexity: Space complexity: Code
G8xd0QPqTy
NORMAL
2025-01-18T05:00:55.556881+00:00
2025-01-18T05:00:55.556881+00:00
10
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code `...
0
0
['C++']
0
minimum-number-of-moves-to-make-palindrome
BIT explanation
bit-explanation-by-dnanper-7h9l
IntuitionApproachComplexity Time complexity: Space complexity: Code
dnanper
NORMAL
2025-01-13T03:20:32.168814+00:00
2025-01-13T03:20:32.168814+00:00
7
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code `...
0
0
['C++']
0
minimum-number-of-moves-to-make-palindrome
Python (simple greedy) - Explained
python-simple-greedy-explained-by-khlie8-vkll
IntuitionExplaining https://leetcode.com/problems/minimum-number-of-moves-to-make-palindrome/solutions/5197436/python-simple-greedyApproachComplexity Time compl
khlie87
NORMAL
2025-01-04T16:32:56.882047+00:00
2025-01-04T16:32:56.882047+00:00
38
false
# Intuition Explaining https://leetcode.com/problems/minimum-number-of-moves-to-make-palindrome/solutions/5197436/python-simple-greedy # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add...
0
0
['Python3']
0
minimum-number-of-moves-to-make-palindrome
Kotlin Two Pointer Approach
kotlin-two-pointer-approach-by-yadunath-f200
IntuitionApproachComplexity Time complexity: Space complexity: Code
yadunath
NORMAL
2024-12-16T15:53:37.592850+00:00
2024-12-16T15:53:37.592850+00:00
2
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)$$ --...
0
0
['Kotlin']
0
minimum-number-of-moves-to-make-palindrome
Kotlin Two Pointer Approach
kotlin-two-pointer-approach-by-yadunath-e52v
IntuitionApproachComplexity Time complexity: Space complexity: Code
yadunath
NORMAL
2024-12-16T15:53:34.823522+00:00
2024-12-16T15:53:34.823522+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)$$ --...
0
0
['Kotlin']
0
minimum-number-of-moves-to-make-palindrome
[Rust] Two pointer solution
rust-two-pointer-solution-by-dinotroll-chdd
IntuitionApproachComplexity Time complexity: O(n2) Space complexity: O(n)CodeIt beat 100% space and time...If that matters to anyone.
dinotroll
NORMAL
2024-12-15T14:05:53.557921+00:00
2024-12-15T14:05:53.557921+00:00
2
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$$O(n^2)$$\n- Space complexity:\n<!-- Add your space complexity here, e.g. $...
0
0
['Rust']
0
minimum-number-of-moves-to-make-palindrome
Two Pointers - Golang Solution
two-pointers-golang-solution-by-sukratia-mwy5
Intuition\nThe problem involves rearranging a string to form a palindrome with the minimum number of adjacent swaps. A palindrome reads the same forwards and ba
sukratiagrawal192
NORMAL
2024-12-04T18:43:36.121406+00:00
2024-12-04T18:43:36.121485+00:00
6
false
# Intuition\nThe problem involves rearranging a string to form a palindrome with the minimum number of adjacent swaps. A palindrome reads the same forwards and backwards, so the characters in the string need to have symmetrical placements around the center.\n\nTo solve this:\n- Focus on matching characters from both en...
0
0
['Two Pointers', 'Go']
0
minimum-number-of-moves-to-make-palindrome
C# || Too Much Greedy Approach
c-too-much-greedy-approach-by-sunil20000-o5pi
csharp []\npublic class Solution {\n public int MinMovesToMakePalindrome(string s) {\n int result = 0, n = s.Length;\n List<char> ls = s.ToList
sunil20000
NORMAL
2024-11-18T14:03:04.623053+00:00
2024-11-18T14:03:04.623100+00:00
16
false
```csharp []\npublic class Solution {\n public int MinMovesToMakePalindrome(string s) {\n int result = 0, n = s.Length;\n List<char> ls = s.ToList();\n while(ls.Count > 0)\n {\n var lastChar = ls[ls.Count - 1];\n var index = ls.FindIndex( c => c == lastChar);\n\n ...
0
0
['Two Pointers', 'Greedy', 'C#']
0
minimum-number-of-moves-to-make-palindrome
C# || Too Much Greedy Approach
c-too-much-greedy-approach-by-sunil20000-lu14
csharp []\npublic class Solution {\n public int MinMovesToMakePalindrome(string s) {\n int result = 0, n = s.Length;\n List<char> ls = s.ToList
sunil20000
NORMAL
2024-11-18T14:02:28.495046+00:00
2024-11-18T14:02:28.495104+00:00
12
false
```csharp []\npublic class Solution {\n public int MinMovesToMakePalindrome(string s) {\n int result = 0, n = s.Length;\n List<char> ls = s.ToList();\n while(ls.Count > 0)\n {\n var lastChar = ls[ls.Count - 1];\n var index = ls.FindIndex( c => c == lastChar);\n\n ...
0
0
['Two Pointers', 'Greedy', 'C#']
0
minimum-number-of-moves-to-make-palindrome
Java | Two Pointers | Beginner Friendly | Clean code with detailed explanation
java-two-pointers-beginner-friendly-clea-vtwe
Greedy Approach\n\n# Intuition\n\nThe goal of the problem is to transform a given string into a palindrome by using a minimum number of adjacent character swaps
ajay_gaulia23
NORMAL
2024-10-24T13:54:48.348077+00:00
2024-10-24T13:54:48.348109+00:00
19
false
# Greedy Approach\n\n# Intuition\n\nThe goal of the problem is to transform a given string into a palindrome by using a minimum number of adjacent character swaps. So the approach revolves around making pairs of characters at symmetric positions until the entire string is symmetrical. **The key is to bring matching cha...
0
0
['Two Pointers', 'String', 'Greedy', 'Java']
0
minimum-number-of-moves-to-make-palindrome
Java Beats 90%
java-beats-90-by-lockmyre-mnks
Intuition\nIt\'s greedy so the intuition is that there is no intuition.\n\n# Code\njava []\nclass Solution {\n public int minMovesToMakePalindrome(String s)
lockmyre
NORMAL
2024-10-19T22:47:47.755861+00:00
2024-10-19T22:47:47.755880+00:00
14
false
# Intuition\nIt\'s greedy so the intuition is that there is no intuition.\n\n# Code\n```java []\nclass Solution {\n public int minMovesToMakePalindrome(String s) {\n return findMinMoves(0, s.length() - 1, s.toCharArray());\n }\n\n private int findMinMoves(int lo, int hi, char[] s) {\n if (lo >= h...
0
0
['Java']
0
minimum-number-of-moves-to-make-palindrome
2193. Minimum Number of Moves to Make Palindrome | TC: O(n^2) for worst case SC: O(1)
2193-minimum-number-of-moves-to-make-pal-dpuk
\n\n## Intuition\nTo determine the minimum number of moves required to rearrange a string into a palindrome, we can leverage the fact that a palindrome reads th
mukeshbala24
NORMAL
2024-10-08T17:21:41.916793+00:00
2024-10-08T17:21:41.916833+00:00
13
false
\n\n## Intuition\nTo determine the minimum number of moves required to rearrange a string into a palindrome, we can leverage the fact that a palindrome reads the same forwards and backwards. Therefore, we need to move characters in such a way that each character has a matching counterpart. The key is to identify how ma...
0
0
['Two Pointers', 'String', 'Greedy', 'Binary Indexed Tree', 'C++']
0
minimum-number-of-moves-to-make-palindrome
Java || Easy to understand || StringBuilder ||
java-easy-to-understand-stringbuilder-by-bbwa
Intuition\n Describe your first thoughts on how to solve this problem. \nThink when any string will be the palindrome ???\n\n# Approach\n Describe your approach
yash_pal2907
NORMAL
2024-09-01T18:20:36.817130+00:00
2024-09-01T18:20:36.817163+00:00
8
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThink when any string will be the palindrome ???\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nWe will use StringBuilder class here to edit/modify the string.\nFirst will check if the last character and first cha...
0
0
['String', 'Greedy', 'Java']
0
difference-between-maximum-and-minimum-price-sum
Re rooting | O(N) | Explained
re-rooting-on-explained-by-java_programm-xap4
Rerooting\nIt is a technique where we solve a given problem for all roots.\n\nSteps\n1. Arbitrary root the tree, lets take node 0 for explanation.\n2. Solve t
Java_Programmer_Ketan
NORMAL
2023-01-15T04:03:46.453216+00:00
2023-01-17T17:19:59.806228+00:00
9,047
false
# Rerooting\n*It is a technique where we solve a given problem for all roots.*\n\n**Steps**\n1. Arbitrary root the tree, lets take `node 0` for explanation.\n2. Solve the given problem as if it was rooted at `node 0`.\n3. Similarily solve the problem for all nodes\n\nEven if you have never heard of this term before,...
103
0
[]
21
difference-between-maximum-and-minimum-price-sum
C++ DFS | one pass | O(n + edge) | beats 100%
c-dfs-one-pass-on-edge-beats-100-by-jaso-604y
IntuitionThis question is similar to 124. Binary Tree Maximum Path Sum but a little different.The difference between this question and 124 are: Only positive va
jason7708
NORMAL
2023-01-15T05:16:04.600358+00:00
2025-01-28T03:29:48.795213+00:00
4,797
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> This question is similar to [124. Binary Tree Maximum Path Sum](https://leetcode.com/problems/binary-tree-maximum-path-sum/) but a little different. The difference between this question and 124 are: 1. Only positive values 2. Not a ...
69
0
['C++']
11
difference-between-maximum-and-minimum-price-sum
✅ Very Simple Python DFS
very-simple-python-dfs-by-0xsapra-lp23
\nclass Solution:\n def maxOutput(self, n: int, edges: List[List[int]], price: List[int]) -> int:\n """\n greedy way could be try each node
0xsapra
NORMAL
2023-01-15T04:29:54.876480+00:00
2023-01-15T05:13:42.115059+00:00
2,632
false
```\nclass Solution:\n def maxOutput(self, n: int, edges: List[List[int]], price: List[int]) -> int:\n """\n greedy way could be try each node as root, but it will be:\n O(N * N) \n \n we can use DP and suddle it down dfs(node, parent) would give correct price ...
24
7
['Python']
9
difference-between-maximum-and-minimum-price-sum
template for tree-based dp problems with edges inputs
template-for-tree-based-dp-problems-with-0x1y
Learned this trick from @yk000123 (https://leetcode.com/problems/minimum-score-after-removals-on-a-tree/discuss/2198125/Python-O(n2)-Iterate-two-edges-with-cach
leetcode_dafu
NORMAL
2023-01-15T04:02:30.321623+00:00
2023-01-15T05:27:25.134708+00:00
3,769
false
Learned this trick from @yk000123 (https://leetcode.com/problems/minimum-score-after-removals-on-a-tree/discuss/2198125/Python-O(n2)-Iterate-two-edges-with-caching\uFF09\n\nFor tree-based dp problems that give you edges as inputs, below is the template\n\n1. store edges into an adjancent list\n2. define a dfs function ...
23
2
['Python']
12
difference-between-maximum-and-minimum-price-sum
DFS vs. BFS
dfs-vs-bfs-by-votrubac-e9kq
A path with maximum cost will always span leaf-to-leaf.\n\nThe cost will be the prices of all nodes in the path, minus the smaller price of two leaves.\n\n####
votrubac
NORMAL
2023-01-21T23:18:05.017232+00:00
2023-01-22T00:13:08.589102+00:00
1,107
false
A path with maximum cost will always span leaf-to-leaf.\n\nThe cost will be the prices of all nodes in the path, minus the smaller price of two leaves.\n\n#### DFS\nWe can run DFS from each leaf, but it will be too slow.\n\nInstead, we can track and return two values from DFS: maximum costs with and without including a...
15
0
['C']
0
difference-between-maximum-and-minimum-price-sum
max path sum | one pass | 🔥 42ms, beats 100% | [Java]
max-path-sum-one-pass-42ms-beats-100-jav-ab2m
NOTE\nthis solution was originally posted by jason7708, and was top voted, not sure why it was later removed, this is the simplest and fasting solution I know,
byegates
NORMAL
2023-01-20T00:09:49.998057+00:00
2023-01-25T19:58:35.382476+00:00
1,223
false
# NOTE\nthis solution was originally posted by [jason7708](https://leetcode.com/jason7708/), and was top voted, not sure why it was later removed, this is the simplest and fasting solution I know, so I am posting it again.\n\n# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n[124. Binary...
14
0
['Java']
4
difference-between-maximum-and-minimum-price-sum
💥💥 Beats 100% on runtime and memory [EXPLAINED]
beats-100-on-runtime-and-memory-explaine-6uqt
IntuitionI noticed that the tree structure allows us to explore paths efficiently from any chosen root node, so I focused on breaking down the problem into mana
r9n
NORMAL
2024-12-27T12:27:21.439309+00:00
2024-12-27T12:27:21.439309+00:00
71
false
# Intuition I noticed that the tree structure allows us to explore paths efficiently from any chosen root node, so I focused on breaking down the problem into manageable subproblems: calculating the maximum path sum starting from each node (in_dp) and the maximum path sum going through the parent node to other branches...
12
0
['Array', 'Dynamic Programming', 'Tree', 'Depth-First Search', 'Graph', 'Rust']
0
difference-between-maximum-and-minimum-price-sum
Java using DFS, Weighted Directed Tree with Comments
java-using-dfs-weighted-directed-tree-wi-v36a
# Intuition \n\n\n# Approach\nThe naive approach asks us to dfs the tree from node u, for every node in the tree.\nThis results in a time complexity of O(n^2)
shiva1718
NORMAL
2023-01-15T04:42:21.449239+00:00
2023-01-16T14:45:16.439870+00:00
2,089
false
<!-- # Intuition -->\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nThe naive approach asks us to dfs the tree from node u, for every node in the tree.\nThis results in a time complexity of O(n^2).\n\nIn order to reduce the time complexity to O(n), we need to try to update maximum p...
12
2
['Tree', 'Depth-First Search', 'Java']
6
difference-between-maximum-and-minimum-price-sum
[C++] Farthest node from each node (+ Additional Practice Problems)
c-farthest-node-from-each-node-additiona-a8io
Difference Between Maximum and Minimum Price Sum\n\nThis is a standard tree problem where it is required find the farthest node from every node. At first glance
Aryan-V-S
NORMAL
2023-01-15T04:35:33.124650+00:00
2023-01-15T18:06:45.007623+00:00
2,104
false
# Difference Between Maximum and Minimum Price Sum\n\nThis is a standard tree problem where it is required find the farthest node from every node. At first glance, the problem seems difficult but with a few observations, it can be made simple. You can practice similar problems on CSES (check out [this](https://cses.fi/...
10
0
['Tree', 'Depth-First Search', 'Breadth-First Search', 'C++']
5
difference-between-maximum-and-minimum-price-sum
C++ understandable code using rerooting
c-understandable-code-using-rerooting-by-mgpa
\n\n\n// firstly i am precomputing the maximum path sum for each node (called sub) using dfs function assuming tree rooted at node 0.\n// Now we are olny left w
avinash1904
NORMAL
2023-01-15T06:53:20.523528+00:00
2023-01-17T21:00:19.496875+00:00
1,478
false
```\n\n\n// firstly i am precomputing the maximum path sum for each node (called sub) using dfs function assuming tree rooted at node 0.\n// Now we are olny left with rerooting at all the nodes and get the maximum of all. I am storing it in dp \n\n//explanation of rerooting function\nconsider the tree\n 0\n\t...
9
1
['Tree', 'Depth-First Search', 'C']
5
difference-between-maximum-and-minimum-price-sum
Python 3 || 16 lines , dfs || T/S: 81 % / 55%
python-3-16-lines-dfs-ts-81-55-by-spauld-3gxt
Here\'s the intuition:\n\n- We assign a three-uplestateto each node. the root and each leaf gets (0,price,0), and each other link\'sstate is determined by the r
Spaulding_
NORMAL
2023-01-17T07:24:31.226895+00:00
2024-06-23T00:46:03.959121+00:00
674
false
Here\'s the intuition:\n\n- We assign a three-uple`state`to each node. the root and each leaf gets `(0,price,0)`, and each other link\'s`state` is determined by the recurence relation in`dfs`. The figure below is for Example 1 in the problem\'s description.\n\n- Best way to figure it out is to trace it from the recuren...
8
2
['Python3']
2
difference-between-maximum-and-minimum-price-sum
Greatest Path Sum Problem - a Variation
greatest-path-sum-problem-a-variation-by-8dqt
Observation\nprice is positive integer, so:\n1. max price sum path should be as long as possible => the path must go to a leaf, and the new root itself must als
antarestrue
NORMAL
2023-01-15T06:13:10.048816+00:00
2023-01-16T07:22:47.704545+00:00
722
false
**Observation**\n`price` is positive integer, so:\n1. max price sum path should be as long as possible => the path must go to a leaf, and the new root itself must also be qualified as a leaf\n2. min price sum path must be only the new root, which is one end of the path\n\nFor (1), there is a boilerplate:\n```\nm = 0\nd...
8
0
['Python']
2
difference-between-maximum-and-minimum-price-sum
C++ DFS + Memo
c-dfs-memo-by-szlin13-ejq4
$O(n^2)$ Easy Solution (AC during contest)\n\nclass Solution {\npublic:\n long long maxOutput(int n, vector<vector<int>>& edges, vector<int>& price) {\n
szlin13
NORMAL
2023-01-15T04:34:03.774328+00:00
2023-01-21T08:10:44.505626+00:00
1,484
false
1. $O(n^2)$ Easy Solution (AC during contest)\n```\nclass Solution {\npublic:\n long long maxOutput(int n, vector<vector<int>>& edges, vector<int>& price) {\n using ll = long long;\n vector<vector<int>> adj(n);\n for (auto& e: edges) {\n adj[e[0]].push_back(e[1]);\n adj[e[1...
6
0
['C++']
3
difference-between-maximum-and-minimum-price-sum
Java , simple DFS + MEMO
java-simple-dfs-memo-by-gavinzhan-0rlb
Java\nclass Solution {\n\tprivate long max;\n\tprivate ArrayList<Integer>[] tree;\n\tprivate int[] price;\n\tprivate long res;\n\tprivate boolean[] visited;\n\n
gavinzhan
NORMAL
2023-01-15T04:03:21.790047+00:00
2023-01-27T01:21:58.341991+00:00
1,713
false
```Java\nclass Solution {\n\tprivate long max;\n\tprivate ArrayList<Integer>[] tree;\n\tprivate int[] price;\n\tprivate long res;\n\tprivate boolean[] visited;\n\n\n\tpublic long maxOutput(int n, int[][] edges, int[] price) {\n\t\tif (n == 1) return 0;\n\n\t\tthis.price = price;\n\t\ttree = new ArrayList[n];\n\t\tfor (...
6
1
[]
1
difference-between-maximum-and-minimum-price-sum
[Python3] DP Tree Re-Rooting - Simple Solution
python3-dp-tree-re-rooting-simple-soluti-zqhc
Intuition\n Describe your first thoughts on how to solve this problem. \n- Problem with tree and asked to find total number satisfy something or find min, max -
dolong2110
NORMAL
2024-08-23T07:54:19.330006+00:00
2024-08-23T07:54:19.330035+00:00
116
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n- Problem with tree and asked to find total number satisfy something or find min, max -> DP tree\n- The problem ask to find something between all the root -> we need re-root.\n- You can find more about DP Tree Re-Rooting [here](https://us...
5
0
['Array', 'Dynamic Programming', 'Tree', 'Graph', 'Python3']
0
difference-between-maximum-and-minimum-price-sum
✅ 🔥 O(n) Python3 || ⚡ solution
on-python3-solution-by-maary-mict
\nfrom typing import List\nfrom collections import defaultdict\n\n\nclass Solution:\n def maxOutput(self, n: int, edges: List[List[int]], price: List[int]) -
maary_
NORMAL
2023-03-13T17:03:08.597295+00:00
2023-03-13T17:03:27.160052+00:00
101
false
```\nfrom typing import List\nfrom collections import defaultdict\n\n\nclass Solution:\n def maxOutput(self, n: int, edges: List[List[int]], price: List[int]) -> int:\n graph = defaultdict(list)\n for a, b in edges:\n graph[a].append(b)\n graph[b].append(a)\n\n def dfs(node...
5
1
['Python', 'Python3']
0
difference-between-maximum-and-minimum-price-sum
JAVA | DFS + Memoization | Approach, Complexities - explained ✅
java-dfs-memoization-approach-complexiti-vc9t
Please Upvote :D\n---\nThis solution is inspired from shiva1718**\njava []\nclass Solution {\n // globally declaring data structure to store the adjacency\n
sourin_bruh
NORMAL
2023-01-15T15:18:37.801846+00:00
2023-01-15T18:23:23.604487+00:00
640
false
# Please Upvote :D\n---\n*This solution is inspired from **[shiva1718](https://leetcode.com/problems/difference-between-maximum-and-minimum-price-sum/solutions/3052821/java-using-dfs-weighted-directed-tree-with-comments/?orderBy=most_votes\n)***\n``` java []\nclass Solution {\n // globally declaring data structure t...
3
0
['Depth-First Search', 'Java']
1
difference-between-maximum-and-minimum-price-sum
Very simple DFS + DP Explained
very-simple-dfs-dp-explained-by-srilekha-22j1
Intuition\n Describe your first thoughts on how to solve this problem. \nAssuming any of the nodes can be root, we will check for each node.\nFor any node:\n
srilekhapaul
NORMAL
2023-01-15T05:47:24.237246+00:00
2023-03-02T16:51:19.479086+00:00
828
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nAssuming any of the nodes can be root, we will check for each node.\nFor any node:\n Mininum sum= node.val (as -ve numbers are not present)\n Maximum sum= node.val + max of all the paths through children ie. Maximum Sum (child) \n\n...
3
0
['Dynamic Programming', 'Depth-First Search', 'Memoization', 'Python', 'Python3']
2
difference-between-maximum-and-minimum-price-sum
C++ || IN - OUT TREE DP || O(n)
c-in-out-tree-dp-on-by-anmol_singh098-hzll
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
Anmol_Singh098
NORMAL
2023-09-02T08:02:18.120022+00:00
2023-09-02T08:02:18.120047+00:00
371
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(Adjacency List Size + 3*N)\n<!-- Add your space c...
2
0
['Dynamic Programming', 'Tree', 'C++']
0
difference-between-maximum-and-minimum-price-sum
c++ || simple || DFS calls
c-simple-dfs-calls-by-12345556-sw7r
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
12345556
NORMAL
2023-08-13T09:46:51.669537+00:00
2023-08-13T09:46:51.669578+00:00
187
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
1
['C++']
0
difference-between-maximum-and-minimum-price-sum
✅ Easy | ✨ O(N) | 🏆 Most Efficient Solution | 👍 Simple Code with Explanations.
easy-on-most-efficient-solution-simple-c-gdkq
Intuition\n Describe your first thoughts on how to solve this problem. \n## Cost simplified\nAccording to the problem description:\n\ncost = maximum price sum -
hero080
NORMAL
2023-05-26T21:59:00.207548+00:00
2023-05-26T21:59:00.207591+00:00
284
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n## Cost simplified\nAccording to the problem description:\n```\ncost = maximum price sum - minimum price sum\n```\nHowever, once you calm down you will notice that the `minimum price sum` is simply the price of the root.\nTherefore the `c...
2
0
['Tree', 'C++']
1
difference-between-maximum-and-minimum-price-sum
C++ || EASY CODE || REROOTING || SIMPLE APPROACH
c-easy-code-rerooting-simple-approach-by-oyu9
Intuition\nBasically we will do two DFS calls.\n\n1) To find the max path from zero.\n\n2) we will have three things to find to get the max path for any node.\n
user3488Hj
NORMAL
2023-02-14T13:14:56.312884+00:00
2023-02-14T13:14:56.312918+00:00
460
false
# Intuition\nBasically we will do two DFS calls.\n\n1) To find the max path from zero.\n\n2) we will have three things to find to get the max path for any node.\n a) sum[x].\n b) parent\'s subtree that is having max path sum (other than subtree we are iterating).\n c) Grand parent\'s that subtree that is havin...
2
0
['Binary Tree', 'C++']
1
difference-between-maximum-and-minimum-price-sum
C++| Root Shifting | O(N)
c-root-shifting-on-by-kumarabhi98-px6x
\nclass Solution {\npublic:\n long long ans = 0;\n int dfs(vector<vector<int>>& nums,vector<int>& val,vector<long long>& sum,int in,int p){\n sum[i
kumarabhi98
NORMAL
2023-01-23T10:49:30.644533+00:00
2023-01-23T10:49:30.644568+00:00
479
false
```\nclass Solution {\npublic:\n long long ans = 0;\n int dfs(vector<vector<int>>& nums,vector<int>& val,vector<long long>& sum,int in,int p){\n sum[in] = val[in];\n long long re = 0;\n for(int i = 0; i<(int)nums[in].size();++i){\n int j = nums[in][i];\n if(j!=p){\n ...
2
0
['Dynamic Programming', 'Tree', 'Depth-First Search', 'Recursion', 'C']
0
difference-between-maximum-and-minimum-price-sum
thought process, 1 dfs, O(n)
thought-process-1-dfs-on-by-jimhorng-omvu
(1) intuitively, try every node as root, find max cost of each path from root\n\n(2) since all nodes\'s price is positive, so minimum path sum will be the root
jimhorng
NORMAL
2023-01-18T13:59:39.939463+00:00
2023-01-21T00:46:17.795708+00:00
366
false
(1) intuitively, try every node as root, find max cost of each path from root\n\n(2) since all nodes\'s price is positive, so minimum path sum will be the root itself, and problems become finding max sum of each path from root substract root\'s price.\nwe can do that with a single dfs, where each node returns the max p...
2
0
['Python']
1
difference-between-maximum-and-minimum-price-sum
[Python] DFS traverse, similar to the maximum path sum problem; Explained
python-dfs-traverse-similar-to-the-maxim-d3e1
This problem is similar to the "maximum path sum" problem.\n\nWe pick any node, and DFS traverse the graph.\n\nFor each of the visiting node, we need to get (1)
wangw1025
NORMAL
2023-01-17T04:38:14.506056+00:00
2023-01-17T04:38:14.506113+00:00
495
false
This problem is similar to the "maximum path sum" problem.\n\nWe pick any node, and DFS traverse the graph.\n\nFor each of the visiting node, we need to get **(1) the maximum path sum with the end node value; and (2) the maximum path sum without the end value**.\n\nSee the details in code:\n\n```\nclass Solution:\n ...
2
0
['Depth-First Search', 'Python3']
1
difference-between-maximum-and-minimum-price-sum
Python dfs solution
python-dfs-solution-by-vincent_great-8jag
\ndef maxOutput(self, n: int, edges: List[List[int]], price: List[int]) -> int:\n\tself.ans, d = 0, defaultdict(list)\n\tfor u, v in edges:\n\t\td[u].append(v)\
vincent_great
NORMAL
2023-01-15T05:36:34.142620+00:00
2023-01-19T18:26:48.766369+00:00
120
false
```\ndef maxOutput(self, n: int, edges: List[List[int]], price: List[int]) -> int:\n\tself.ans, d = 0, defaultdict(list)\n\tfor u, v in edges:\n\t\td[u].append(v)\n\t\td[v].append(u)\n\n\tdef dfs(i, fi):\n\t\tmx1, mx2 = price[i], 0\n\t\tfor x in d[i]:\n\t\t\tif x != fi:\n\t\t\t\ts1, s2 = dfs(x, i)\n\t\t\t\tself.ans = m...
2
1
[]
1
difference-between-maximum-and-minimum-price-sum
O(n) | Re-rooting | c++
on-re-rooting-c-by-betoscl-aqwj
Intuition\nprecalculate the best paths if we had 0 as root and then re-root and update those values \u200B\u200Bin $O(1)$\n\n# Approach\nFirst we need to find t
BetoSCL
NORMAL
2023-01-15T04:33:25.805321+00:00
2023-01-15T04:33:25.805378+00:00
724
false
# Intuition\nprecalculate the best paths if we had 0 as root and then re-root and update those values \u200B\u200Bin $O(1)$\n\n# Approach\nFirst we need to find the answer for root 0, so we keep a kind of $DP$ that says the best answer for each node if we start from there and just go down, with this $DP$ the answer wil...
2
1
['C++']
0
difference-between-maximum-and-minimum-price-sum
[Python3] dfs
python3-dfs-by-ye15-uf5g
\n\nclass Solution:\n def maxOutput(self, n: int, edges: List[List[int]], price: List[int]) -> int:\n tree = [[] for _ in range(n)]\n for u, v
ye15
NORMAL
2023-01-15T04:16:58.696932+00:00
2023-01-15T04:16:58.696973+00:00
394
false
\n```\nclass Solution:\n def maxOutput(self, n: int, edges: List[List[int]], price: List[int]) -> int:\n tree = [[] for _ in range(n)]\n for u, v in edges: \n tree[u].append(v)\n tree[v].append(u)\n \n def dfs(u, p): \n """Return """\n nonlocal ...
2
1
['Python3']
0
difference-between-maximum-and-minimum-price-sum
C++ | 2 DFS | Pre-calculate for root 0
c-2-dfs-pre-calculate-for-root-0-by-kena-jxf1
Code
kenA7
NORMAL
2025-04-01T04:54:57.680228+00:00
2025-04-01T04:54:57.680228+00:00
19
false
# Code ```cpp [] class Solution { public: #define ll long long vector<ll>maxCost; ll calculateCostForRoot0(int u,int p, vector<vector<int>>&g,vector<int>& price) { ll res=0; for(auto &v:g[u]) { if(v==p) continue; res=max(res,calculateCostFo...
1
0
['C++']
0
difference-between-maximum-and-minimum-price-sum
IN OUT DP || SIMPLE APPROACH || CSES Standard
in-out-dp-simple-approach-cses-standard-xbhnn
Intuition\n Describe your first thoughts on how to solve this problem. \nThe idea is same as of a CSES Tree Distance I problem.\n\nWe are here using in out dp i
asif_0077
NORMAL
2024-04-05T22:52:26.127524+00:00
2024-04-05T22:52:26.127541+00:00
40
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe idea is same as of a [CSES Tree Distance I](https://cses.fi/problemset/task/1132) problem.\n\nWe are here using in out dp in which we have in and out arrays by which we are at every node we have max path sum in its subtree using in ar...
1
0
['Dynamic Programming', 'Graph', 'C++']
0
difference-between-maximum-and-minimum-price-sum
DP ON TREES || SIMILAR TO TREE DISTANCE 1
dp-on-trees-similar-to-tree-distance-1-b-8gzv
\n\nclass Solution {\npublic:\n vector<vector<int>>g;\n vector<long long>d,ans;\n void f1(int s,int p,vector<int>& pr){\n long long a=pr[s];\n
Agam_Raizada
NORMAL
2024-03-11T20:41:25.470908+00:00
2024-03-11T20:41:25.470940+00:00
22
false
\n```\nclass Solution {\npublic:\n vector<vector<int>>g;\n vector<long long>d,ans;\n void f1(int s,int p,vector<int>& pr){\n long long a=pr[s];\n for(int c:g[s]){\n if(c!=p){\n f1(c,s,pr);\n a=max(a,pr[s]+d[c]);\n }\n }\n d[s]=a;\n...
1
0
['Dynamic Programming', 'Tree', 'C++']
0
difference-between-maximum-and-minimum-price-sum
C++ | Rerooting
c-rerooting-by-user4957x-zl33
Intuition\nEasy to solve id rooted, so solve for a random root, and reroot the tree.\n\n# Approach\nRerooting\n\n# Complexity\n- Time complexity:\nO(n)\n\n- Spa
user4957x
NORMAL
2024-02-03T19:16:29.454019+00:00
2024-02-03T19:17:52.705622+00:00
25
false
# Intuition\nEasy to solve id rooted, so solve for a random root, and reroot the tree.\n\n# Approach\nRerooting\n\n# Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(n)\n\n# Code\n```\nclass Solution {\npublic:\n long long maxOutput(int n, vector<vector<int>>& edges, vector<int>& price) {\n vect...
1
0
['C++']
1
difference-between-maximum-and-minimum-price-sum
💡Rerooting Easy to understant solution
rerooting-easy-to-understant-solution-by-a6e0
Intuition\n Describe your first thoughts on how to solve this problem. \nAll the best with your coding preparation, This is new approach so don\'t be discourage
omkarkawatgi
NORMAL
2023-11-22T12:22:40.820831+00:00
2023-11-22T12:22:40.820860+00:00
47
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nAll the best with your coding preparation, This is new approach so don\'t be discouraged if you were not able to solve it... Keep learning, keep growing. Let me know any doubts...\n \n\n# Approach\n<!-- Describe your approach to solving t...
1
0
['Tree', 'Depth-First Search', 'C++']
0
difference-between-maximum-and-minimum-price-sum
Re-rooting Tree dp || Happy Coding
re-rooting-tree-dp-happy-coding-by-vikas-b3bg
Intuition\nThis is a re-rooting tree dp problem \n\n# Approach\nfirst find the solution for any one node as a root ( eg. 0);\nthat is what dfs(0, -1) is finding
vikas58616
NORMAL
2023-08-05T22:40:48.960261+00:00
2023-08-05T22:40:48.960283+00:00
47
false
# Intuition\nThis is a re-rooting tree dp problem \n\n# Approach\nfirst find the solution for any one node as a root ( eg. 0);\nthat is what dfs(0, -1) is finding \n\nthen we need to update the root that is done using dfs2(-1, 0, 0);\nfunction\nthe below implementation is a standard template for rerooting the tree\nste...
1
0
['Array', 'Dynamic Programming', 'Tree', 'Depth-First Search', 'C++']
0
difference-between-maximum-and-minimum-price-sum
O(n) || DFS || C++
on-dfs-c-by-kavascgjmd39-7tza
Intuition\n Describe your first thoughts on how to solve this problem. \nThe question was difficult so if you cant do it is fine. I solved it after fixing vario
kavascgjmd39
NORMAL
2023-07-03T07:36:05.074506+00:00
2023-07-03T07:37:06.538676+00:00
55
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe question was difficult so if you cant do it is fine. I solved it after fixing various cases in O(n)\nIf i rewrite the question it is give me the sum of maxium path\nfrom the root node to leaf node without considering root node (as roo...
1
0
['C++']
0
difference-between-maximum-and-minimum-price-sum
Easy DP On Tree C++ || Kartik Arora Style
easy-dp-on-tree-c-kartik-arora-style-by-n5yb0
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
dtom7628
NORMAL
2023-06-20T15:20:19.747829+00:00
2023-06-20T15:20:19.747846+00:00
216
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:\n<!-- Add your space complexity here, e.g. $$O(n)...
1
0
['Dynamic Programming', 'Tree', 'Depth-First Search', 'C++']
0
difference-between-maximum-and-minimum-price-sum
Re rooting | O(N) clean code
re-rooting-on-clean-code-by-w2024-ds9r
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
w2024
NORMAL
2023-01-17T12:23:49.486899+00:00
2023-01-17T12:23:49.486936+00:00
1,041
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
difference-between-maximum-and-minimum-price-sum
[Python] explanation of `DFS + cache` approach
python-explanation-of-dfs-cache-approach-dgpl
python\nclass Solution:\n def maxOutput(self, n: int, edges: List[List[int]], price: List[int]) -> int:\n g = defaultdict(list)\n \n for
pbelskiy
NORMAL
2023-01-16T21:58:51.300617+00:00
2023-01-16T22:00:35.099038+00:00
101
false
```python\nclass Solution:\n def maxOutput(self, n: int, edges: List[List[int]], price: List[int]) -> int:\n g = defaultdict(list)\n \n for a, b in edges:\n g[a].append(b)\n g[b].append(a)\n \n @cache\n def dfs(i, p):\n r = 0\n\n for j in...
1
0
['Depth-First Search', 'Memoization']
0
difference-between-maximum-and-minimum-price-sum
C++ DFS 100% Faster
c-dfs-100-faster-by-rook_lift-3by7
\n#define ll long long int \nclass Solution {\npublic:\n ll ans=0;\n \n vector<ll> vec[100005];\n ll mx[100005];\n \n void dfs1(ll u, ll p , vector<int>
Rook_Lift
NORMAL
2023-01-16T18:06:54.349814+00:00
2023-01-16T18:06:54.349859+00:00
323
false
```\n#define ll long long int \nclass Solution {\npublic:\n ll ans=0;\n \n vector<ll> vec[100005];\n ll mx[100005];\n \n void dfs1(ll u, ll p , vector<int>&a)\n {\n mx[u]=0;\n \n for(ll v:vec[u])\n {\n if(v==p) continue;\n dfs1(v,u,a);\n mx[u]=max(mx[u], mx[v]);\n }\n mx[u]+...
1
0
[]
0
difference-between-maximum-and-minimum-price-sum
[java] ✔ One of the easiest solution DFS + DP || Explanation
java-one-of-the-easiest-solution-dfs-dp-tk1yn
\npublic static long maxOutput(int n, int[][] edges, int[] price) {\n Map<String, Long> map = new HashMap<>();\n List<List<Integer>> adj = new Arr
atul-chaudhary
NORMAL
2023-01-16T09:43:32.917635+00:00
2023-01-16T09:43:32.917684+00:00
107
false
```\npublic static long maxOutput(int n, int[][] edges, int[] price) {\n Map<String, Long> map = new HashMap<>();\n List<List<Integer>> adj = new ArrayList<>();\n for (int i = 0; i < n; i++) {\n adj.add(new ArrayList<>());\n }\n\n for (int i = 0; i < edges.length; i++) {\n ...
1
0
['Dynamic Programming', 'Depth-First Search', 'Java']
0
difference-between-maximum-and-minimum-price-sum
Java | two dfs
java-two-dfs-by-conchwu-rxwn
\n //2.two DFS\n //Runtime: 105ms 100%; Memory 99.1MB 100%\n //Time: O(N); Space: O(N);\n public long maxOutput(int n, int[][] edges, int[] price) {
conchwu
NORMAL
2023-01-15T18:32:21.173075+00:00
2023-01-15T18:32:21.173119+00:00
526
false
```\n //2.two DFS\n //Runtime: 105ms 100%; Memory 99.1MB 100%\n //Time: O(N); Space: O(N);\n public long maxOutput(int n, int[][] edges, int[] price) {\n List<Integer>[] graph = new List[n];\n for (int i = 0; i < n; i++)\n graph[i] = new ArrayList<>();\n\n for(int[] edge: edg...
1
0
['Depth-First Search', 'Java']
1
difference-between-maximum-and-minimum-price-sum
Rust DFS and Backtracking
rust-dfs-and-backtracking-by-xiaoping341-fis0
Intuition\n Describe your first thoughts on how to solve this problem. \nUse DFS twice, with the first one to calculate maximum cost of each subtree, and the se
xiaoping3418
NORMAL
2023-01-15T17:00:01.968064+00:00
2023-01-16T11:47:02.625147+00:00
226
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nUse DFS twice, with the first one to calculate maximum cost of each subtree, and the second to calculate the answer with rerooting on a child. \n# Approach\n<!-- Describe your approach to solving the problem. -->\n1) Use dfs to calculat...
1
0
['Rust']
0
difference-between-maximum-and-minimum-price-sum
Java DFS+Memoriazation with explanation
java-dfsmemoriazation-with-explanation-b-nnoy
Intuition\nThe idea that I have when seeing the problem is to use DFS. \n- Build an adjacent table(HashMap) to record the neighbor point for each node;\n- in th
XYH10022
NORMAL
2023-01-15T15:06:31.566899+00:00
2023-01-15T15:06:31.566942+00:00
392
false
# Intuition\nThe idea that I have when seeing the problem is to use DFS. \n- Build an adjacent table(HashMap) to record the neighbor point for each node;\n- in the method of dfs, pass the current ndoe and its parent node(from where we traverse to current node)\n- \nBut the time complexity for it can be terrible since w...
1
0
['Java']
1
difference-between-maximum-and-minimum-price-sum
✅ JavaScript || Easy || DFS || Memoization || Commented
javascript-easy-dfs-memoization-commente-s97d
\n\n\n```\n/*\n * @param {number} n\n * @param {number[][]} edges\n * @param {number[]} price\n * @return {number}\n /\nvar maxOutput = function(n, edges, price
Atikur-Rahman-Sabuj
NORMAL
2023-01-15T14:48:04.572504+00:00
2023-01-15T14:48:31.440945+00:00
259
false
\n\n\n```\n/**\n * @param {number} n\n * @param {number[][]} edges\n * @param {number[]} price\n * @return {number}\n */\nvar maxOutput = function(n, edges, price) {\n const m = new Array(n).fill(null).map(_=> new Map());\n for(const edge of edges){\n // initialize graph and path values with 0\n m[ed...
1
0
['Depth-First Search', 'Memoization', 'JavaScript']
1
difference-between-maximum-and-minimum-price-sum
Three diffrent solutions
three-diffrent-solutions-by-g129512-q8jy
Solution 1\n- Enumerate the root nodes and find the maximum path sum from each root node to the leaf. \n- Pass the maximum path sum from parent branch during DF
g129512
NORMAL
2023-01-15T09:31:16.632404+00:00
2023-01-15T10:11:49.424142+00:00
455
false
## Solution 1\n- Enumerate the root nodes and find the maximum path sum from each root node to the leaf. \n- Pass the maximum path sum from parent branch during DFS. \n\n```\n\nclass Solution:\n def maxOutput(self, n: int, edges: List[List[int]], price: List[int]) -> int:\n g=[[] for _ in range(n)]\n f...
1
0
['Dynamic Programming', 'Depth-First Search']
0
difference-between-maximum-and-minimum-price-sum
Better than most voted | Easiest C++ | Brute Force Memoisation
better-than-most-voted-easiest-c-brute-f-g1r0
Just use the brute force approach and memoise it using map.\nYes, it\'s that simple.\n\nNote: We are not using a dp[n][n] here because creating this only will t
AnujJadhav
NORMAL
2023-01-15T05:26:16.258604+00:00
2023-01-15T05:27:21.051995+00:00
141
false
Just use the brute force approach and memoise it using map.\nYes, it\'s that simple.\n\nNote: We are not using a ```dp[n][n]``` here because creating this only will take ```O(n^2)``` time, whereas not every node is going to have n childrens, this is where map comes handy.\n\nC++ code:\n```\nclass Solution {\npublic:\n ...
1
0
['Dynamic Programming', 'Tree', 'Memoization']
0
difference-between-maximum-and-minimum-price-sum
damn just need one more line to get AK this week 😭
damn-just-need-one-more-line-to-get-ak-t-jzrf
\n# Approach\n Describe your approach to solving the problem. \nuse dfs to build max price of each node\ndon\'t look at my code, its too complex and not elegant
ZhonghaoLuo
NORMAL
2023-01-15T05:06:07.524409+00:00
2023-01-15T05:08:54.950336+00:00
431
false
\n# Approach\n<!-- Describe your approach to solving the problem. -->\nuse dfs to build max price of each node\ndon\'t look at my code, its too complex and not elegant\n# 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 complexit...
1
0
['Python3']
1
difference-between-maximum-and-minimum-price-sum
[Python] 2 DFS
python-2-dfs-by-shadofren-dg6a
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
shadofren
NORMAL
2023-01-15T04:58:27.795889+00:00
2023-01-15T05:00:41.383545+00:00
357
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)$$ -->\nO(n)\n\n- Space complexity:\nO(n)\n\n# Code\n```\nclass Solution:\n def m...
1
0
['Python3']
0
difference-between-maximum-and-minimum-price-sum
🔥 Python 🔥 | Simple code | DFS + MEMO
python-simple-code-dfs-memo-by-hululu040-aipb
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
hululu0405
NORMAL
2023-01-15T04:37:42.777336+00:00
2023-01-15T04:39:05.117852+00:00
258
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
1
['Depth-First Search', 'Python3']
1
difference-between-maximum-and-minimum-price-sum
DP - TopDown | Java
dp-topdown-java-by-nisarg_pat-ste6
Intuition\n Describe your first thoughts on how to solve this problem. \nDP: dp(u,v) (Node.max in the program) would store the maximum path length from v consid
Nisarg_Pat
NORMAL
2023-01-15T04:36:55.053314+00:00
2023-01-15T04:51:35.084860+00:00
515
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nDP: dp(u,v) (Node.max in the program) would store the maximum path length from v considering u as the parent node.\n\ndp(u,v) = price[v]+max(dp(v, w)) where w belongs to {adj[v]} - {u}.\n\nUsing memoization to store all the values of (u,v...
1
0
['Dynamic Programming', 'Memoization', 'Java']
1
difference-between-maximum-and-minimum-price-sum
[C++] dfs, bfs, memo
c-dfs-bfs-memo-by-lovelydays95-x7zg
use bfs to avoid stack over flow for 1e5 nodes\n\nclass Solution {\n long long res = -1;\n vector<pair<long long, long long>> val;\n vector<vector<long
lovelydays95
NORMAL
2023-01-15T04:30:29.149042+00:00
2023-01-15T04:30:29.149073+00:00
189
false
use bfs to avoid stack over flow for 1e5 nodes\n```\nclass Solution {\n long long res = -1;\n vector<pair<long long, long long>> val;\n vector<vector<long long>> adj;\n vector<long long> P;\n void dfs(long long u, long long par) {\n val[u] = {0,P[u]};\n for(auto& v : adj[u]) {\n ...
1
0
[]
0
difference-between-maximum-and-minimum-price-sum
Python BFS, DP on trees approach
python-bfs-dp-on-trees-approach-by-c410n-e8i8
null
c410n
NORMAL
2025-02-27T05:29:16.403711+00:00
2025-02-27T05:29:16.403711+00:00
5
false
``` from typing import List import collections class Solution: def maxOutput(self, n: int, edges: List[List[int]], price: List[int]) -> int: AL = collections.defaultdict(list) for b, e in edges: AL[b].append(e) AL[e].append(b) visited = set() max_down = [p ...
0
0
['Python3']
0
difference-between-maximum-and-minimum-price-sum
scala dfs. inelastic snakes on a tree in a knapsack with a hole
scala-dfs-inelastic-snakes-on-a-tree-in-cz3c3
so we have a bag (maybe a knapsack) with a tree inside and with snakes fixed at tree nodes.heads and tail tips are at root or leaves.a hole is as tree root (can
vititov
NORMAL
2025-02-22T14:31:29.283681+00:00
2025-02-22T14:35:24.017144+00:00
4
false
so we have a bag (maybe a knapsack) with a tree inside and with snakes fixed at tree nodes. heads and tail tips are at root or leaves. a hole is as tree root (can be any node, i.e. e.g.: 0) we can catch shakes at body, head or tail tip. we want to find a snake with a "biggest tail" (body + tail tip). of course, we cann...
0
0
['Scala']
0
difference-between-maximum-and-minimum-price-sum
Python Hard
python-hard-by-lucasschnee-4h6s
null
lucasschnee
NORMAL
2025-02-07T18:08:35.634388+00:00
2025-02-07T18:08:35.634388+00:00
3
false
```python3 [] class Solution: def maxOutput(self, n: int, edges: List[List[int]], price: List[int]) -> int: lookup = defaultdict(list) for u, v in edges: lookup[u].append(v) lookup[v].append(u) self.best = 0 lookup_mxs = defaultdict(list) # get two...
0
0
['Python3']
0
difference-between-maximum-and-minimum-price-sum
DFS, O(n) TC
dfs-on-tc-by-filinovsky-t2f9
IntuitionApproachComplexity Time complexity: Space complexity: Code
Filinovsky
NORMAL
2025-01-29T11:12:39.416500+00:00
2025-01-29T11:12:39.416500+00:00
6
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code `...
0
0
['Python3']
0
difference-between-maximum-and-minimum-price-sum
2538. Difference Between Maximum and Minimum Price Sum
2538-difference-between-maximum-and-mini-fxf6
IntuitionApproachComplexity Time complexity: Space complexity: Code
G8xd0QPqTy
NORMAL
2025-01-19T01:46:32.422646+00:00
2025-01-19T01:46:32.422646+00:00
9
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code `...
0
0
['Python3']
0
difference-between-maximum-and-minimum-price-sum
✅DFS || PYTHON
dfs-python-by-darkenigma-zdvp
\n# Code\npython3 []\nclass Solution:\n def dfs(self,gra,dis,i,par,price):\n for j in gra[i]:\n if(j==par):continue\n a=self.dfs
darkenigma
NORMAL
2024-12-08T14:27:00.362430+00:00
2024-12-08T14:27:00.362464+00:00
6
false
\n# Code\n```python3 []\nclass Solution:\n def dfs(self,gra,dis,i,par,price):\n for j in gra[i]:\n if(j==par):continue\n a=self.dfs(gra,dis,j,i,price)\n if(a>dis[i][0]):\n a^=dis[i][0]\n dis[i][0]^=a\n a^=dis[i][0]\n if(a...
0
0
['Array', 'Dynamic Programming', 'Tree', 'Depth-First Search', 'Python3']
0
difference-between-maximum-and-minimum-price-sum
Rerooting the tree
rerooting-the-tree-by-pikachu0123-xyzx
Intuition\nBasically finding out the max path for each subtree (precomputing).\nThen keep track of the max path for the upper tree while traversing.\n\nTake max
Pikachu0123
NORMAL
2024-10-30T06:19:39.392416+00:00
2024-10-30T06:19:39.392452+00:00
9
false
# Intuition\nBasically finding out the max path for each subtree (precomputing).\nThen keep track of the max path for the upper tree while traversing.\n\nTake maximum of both, and update this value for the lower subtrees\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time comple...
0
0
['C++']
0
difference-between-maximum-and-minimum-price-sum
Python (Simple DFS)
python-simple-dfs-by-rnotappl-76a5
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
rnotappl
NORMAL
2024-10-28T09:53:10.418500+00:00
2024-10-28T09:53:10.418524+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)$$ --...
0
0
['Python3']
0
difference-between-maximum-and-minimum-price-sum
Two Pass Solution O(N)
two-pass-solution-on-by-nag007-0ave
\n\n# Code\npython3 []\nclass Solution:\n def maxOutput(self, n: int, edges: List[List[int]], price: List[int]) -> int:\n \n ans = 0\n\n
nag007
NORMAL
2024-10-14T17:03:32.835887+00:00
2024-10-14T17:03:32.835919+00:00
3
false
\n\n# Code\n```python3 []\nclass Solution:\n def maxOutput(self, n: int, edges: List[List[int]], price: List[int]) -> int:\n \n ans = 0\n\n @lru_cache(None)\n def first_pass(current_node,parent_node = -1):\n\n max_price = 0\n for next_node in x[current_node]:\n ...
0
0
['Python3']
0
difference-between-maximum-and-minimum-price-sum
Don't try this at your Home Coding😂❤️
dont-try-this-at-your-home-coding-by-ath-fc4q
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
Athar4403
NORMAL
2024-10-05T04:44:12.216666+00:00
2024-10-05T04:44:12.216695+00:00
8
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)$$ --...
0
0
['C++']
0
difference-between-maximum-and-minimum-price-sum
In Out DP
in-out-dp-by-kndudhushyanthan-nxel
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
kndudhushyanthan
NORMAL
2024-10-03T12:31:16.186155+00:00
2024-10-03T12:31:16.186179+00:00
8
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)$$ --...
0
0
['C++']
0
difference-between-maximum-and-minimum-price-sum
Re-rooting DP with maximum and second_maximum || Easy and well-explained ||
re-rooting-dp-with-maximum-and-second_ma-0gwm
Intuition\nTree Re-rooting using maximum and second-maximum value\n\n# Approach\n- First I have created a 2D Dp vector where for ith node, dp[i][0] will store m
tmohit_04
NORMAL
2024-10-02T07:29:56.274210+00:00
2024-10-02T07:29:56.274241+00:00
12
false
# Intuition\nTree Re-rooting using maximum and second-maximum value\n\n# Approach\n- First I have created a 2D Dp vector where for ith node, dp[i][0] will store maximum value of all the subtree paths and dp[i][1] will store the second maximum.\n- Two DFS calls will be made just like usual re-rooting problems.\n- 1st DF...
0
0
['Dynamic Programming', 'Depth-First Search', 'C++']
0
difference-between-maximum-and-minimum-price-sum
Runtime Beats 100% Java Users || Explanation Includes Algorithm Used, Why and Alternative(s)
runtime-beats-100-java-users-explanation-momn
Explanation of the Code\n\nThe goal of this code is to solve a problem involving a tree where each node has a certain "price" (a numeric value), and the task is
Adrian_A
NORMAL
2024-09-26T13:22:49.768767+00:00
2024-09-26T13:22:49.768788+00:00
10
false
### Explanation of the Code\n\nThe goal of this code is to solve a problem involving a tree where each node has a certain "price" (a numeric value), and the task is to find the maximum possible "output" (sum of prices along a path) that can be achieved in the tree. The tree is represented using an adjacency list.\n\n##...
0
0
['Array', 'Dynamic Programming', 'Tree', 'Depth-First Search', 'Java']
0
difference-between-maximum-and-minimum-price-sum
Manual rerooting | In-out rerooting | Commented
manual-rerooting-in-out-rerooting-commen-6ppp
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
anonymous_k
NORMAL
2024-09-26T08:41:45.267469+00:00
2024-09-26T08:41:45.267504+00:00
4
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)$$ --...
0
0
['Python3']
0
difference-between-maximum-and-minimum-price-sum
Use DFS and ReRoot
use-dfs-and-reroot-by-thevu870-amjt
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n- Use 2 DFS\n- 1st DFS: find biggest path at each sub tree so we can find
thevu870
NORMAL
2024-08-28T08:02:39.530209+00:00
2024-08-28T08:02:39.530252+00:00
13
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n- Use 2 DFS\n- 1st DFS: find biggest path at each sub tree so we can find biggest path of tree start with root = node 0.\n- 2nd DFS: Currently we have info of tree with root = node 0, now if we try to change root from node 0...
0
0
['C++']
0