filmov
tv
Find the Maximum Sum of Node Values | Two Approaches | Detailed | Leetcode 3068 | codestorywithMIK

Показать описание
This is the 33rd Video of our Playlist "Greedy : Popular Interview Problems" by codestorywithMIK
In this video we will try to solve a good Greedy problem : Find the Maximum Sum of Node Values | Greedy | Two Approaches | Detailed | Leetcode 3068 | codestorywithMIK
I will explain the intuition so easily that you will never forget and start seeing this as cakewalk EASYYY.
We will do live coding after explanation and see if we are able to pass all the test cases.
Also, please note that my Github solution link below contains both C++ as well as JAVA code.
Problem Name : Find the Maximum Sum of Node Values | Greedy | Two Approaches | Detailed | Leetcode 3068 | codestorywithMIK
Company Tags : Google
╔═╦╗╔╦╗╔═╦═╦╦╦╦╗╔═╗
║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣
╠╗║╚╝║║╠╗║╚╣║║║║║═╣
╚═╩══╩═╩═╩═╩╝╚╩═╩═╝
Summary :
**Approach-1 (Greedily picking nodes to XOR)**:
This approach iterates through the given list of numbers. For each number, it calculates the XOR value with a given constant 'k'. If the XOR value is greater than the original number, it adds this XOR value to the sum, otherwise, it adds the original number. Additionally, it keeps track of the minimum difference between each number and its XOR value. After iterating through all numbers, if the count of numbers with XOR values greater than themselves is even, it returns the sum. Otherwise, it subtracts the minimum difference from the sum before returning it.
**Time Complexity (T.C)**: O(n)
**Space Complexity (S.C)**: O(1)
**Approach-2 (Greedy + Sorting)**:
This approach also iterates through the given list of numbers. For each number, it calculates the potential gain (fayda) by XORing it with the given constant 'k' and subtracting the original number. It sums up the original numbers. Then, it sorts the potential gain values in descending order. It iterates through the sorted potential gain values in pairs and adds the sum of positive pairs to the original sum.
**Time Complexity (T.C)**: O(nlogn)
**Space Complexity (S.C)**: O(n)
✨ Timelines✨
00:00 - Introduction
00:16 - Problem Explanation
4:16 - Approach-1 Intuition
32:15 - Coding Approach-1
35:17 - Approach-2 Intuition
43:25 - Coding Approach-2
#coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge #leetcodequestions #leetcodechallenge #hindi #india #coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge#leetcodequestions #leetcodechallenge #hindi #india #hindiexplanation #hindiexplained #easyexplaination #interview#interviewtips #interviewpreparation #interview_ds_algo #hinglish #github #design #data #google #video #instagram #facebook #leetcode #computerscience #leetcodesolutions #leetcodequestionandanswers #code #learning #dsalgo #dsa #newyear2024
In this video we will try to solve a good Greedy problem : Find the Maximum Sum of Node Values | Greedy | Two Approaches | Detailed | Leetcode 3068 | codestorywithMIK
I will explain the intuition so easily that you will never forget and start seeing this as cakewalk EASYYY.
We will do live coding after explanation and see if we are able to pass all the test cases.
Also, please note that my Github solution link below contains both C++ as well as JAVA code.
Problem Name : Find the Maximum Sum of Node Values | Greedy | Two Approaches | Detailed | Leetcode 3068 | codestorywithMIK
Company Tags : Google
╔═╦╗╔╦╗╔═╦═╦╦╦╦╗╔═╗
║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣
╠╗║╚╝║║╠╗║╚╣║║║║║═╣
╚═╩══╩═╩═╩═╩╝╚╩═╩═╝
Summary :
**Approach-1 (Greedily picking nodes to XOR)**:
This approach iterates through the given list of numbers. For each number, it calculates the XOR value with a given constant 'k'. If the XOR value is greater than the original number, it adds this XOR value to the sum, otherwise, it adds the original number. Additionally, it keeps track of the minimum difference between each number and its XOR value. After iterating through all numbers, if the count of numbers with XOR values greater than themselves is even, it returns the sum. Otherwise, it subtracts the minimum difference from the sum before returning it.
**Time Complexity (T.C)**: O(n)
**Space Complexity (S.C)**: O(1)
**Approach-2 (Greedy + Sorting)**:
This approach also iterates through the given list of numbers. For each number, it calculates the potential gain (fayda) by XORing it with the given constant 'k' and subtracting the original number. It sums up the original numbers. Then, it sorts the potential gain values in descending order. It iterates through the sorted potential gain values in pairs and adds the sum of positive pairs to the original sum.
**Time Complexity (T.C)**: O(nlogn)
**Space Complexity (S.C)**: O(n)
✨ Timelines✨
00:00 - Introduction
00:16 - Problem Explanation
4:16 - Approach-1 Intuition
32:15 - Coding Approach-1
35:17 - Approach-2 Intuition
43:25 - Coding Approach-2
#coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge #leetcodequestions #leetcodechallenge #hindi #india #coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge#leetcodequestions #leetcodechallenge #hindi #india #hindiexplanation #hindiexplained #easyexplaination #interview#interviewtips #interviewpreparation #interview_ds_algo #hinglish #github #design #data #google #video #instagram #facebook #leetcode #computerscience #leetcodesolutions #leetcodequestionandanswers #code #learning #dsalgo #dsa #newyear2024
Комментарии