Distribute candies in a binary tree | Intuition | Story To Code | GfG POTD
Whatsapp Community Link : https://www.whatsapp.com/channel/0029Va6kVSjICVfiVdsHgi1A
This is the 36th Video of our Playlist "Binary Tree : Popular Interview Problems".
In this video we will try to solve a good Binary Tree problem - Distribute candies in a binary tree
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 : Distribute candies in a binary tree (GfG POTD)
Company Tags : Microsoft
My solutions on Github(C++ & JAVA) : https://github.com/MAZHARMIK/Interview_DS_Algo/blob/master/Tree/Distribute%20candies%20in%20a%20binary%20tree.cpp
GfG Link : https://www.geeksforgeeks.org/problems/distribute-candies-in-a-binary-tree/1
My DP Concepts Playlist : https://youtu.be/7eLMOE1jnls
My Graph Concepts Playlist : https://youtu.be/5JGiZnr6B5w
My GitHub Repo for interview preparation : https://github.com/MAZHARMIK/Interview_DS_Algo
Subscribe to my channel : https://www.youtube.com/@codestorywithMIK
Instagram : https://www.instagram.com/codestorywithmik/
Facebook : https://www.facebook.com/people/codestorywithmik/100090524295846/
Twitter : https://twitter.com/CSwithMIK
Approach Summary : In the solve function, a recursive approach is used to traverse the binary tree. For each node, the function calculates the total number of extra candies that can be distributed among its left and right subtrees, along with the candies at the current node. The function also updates the moves variable to keep track of the total number of moves required to distribute candies. The distributeCandy function initializes the moves variable and checks if the tree has only one node. If it does, the function returns 0. Otherwise, it calls the solve function to perform the candy distribution and returns the total number of moves required. Overall, the code implements a candy distribution algorithm for a binary tree, aiming to minimize the total number of moves while ensuring each node receives an appropriate number of candies.
╔═╦╗╔╦╗╔═╦═╦╦╦╦╗╔═╗
║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣
╠╗║╚╝║║╠╗║╚╣║║║║║═╣
╚═╩══╩═╩═╩═╩╝╚╩═╩═╝
✨ Timelines✨
00:00 - Introduction
#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 #2024 #newyear