HackerRank - Equal | Full Solution with Simplified Examples and Visuals | Study Algorithms

preview_player
Показать описание
In this problem you want to ensure that all the employees have an equal number of chocolate distribution. However, you can only give 1, 2, or 5 chocolates at a time. You give chocolates to everyone but 1 employee. In this video I explain the test cases to understand it in a perfect way. Then watch the video to see how I simplify the problem using a very neat trick. All along with visuals and explanations.

Chapters:
00:00 - Intro
01:06 - Problem statement and description
05:08 - Simplification of problem
09:00 - How to Solve?
14:28 - Dry-run of Code
19:24 - Final Thoughts

📚 Links to topics I talk about in the video:

📖 Reference Books:

🎥 My Recording Gear:

💻 Get Social 💻

#hackerrank #programming #interview
Рекомендации по теме
Комментарии
Автор

Thanks brother! Finally I understood it. The visuals and explanation were really good.

doingsneakypeakylike
Автор

Nice solution, we can have only three possibilites[ will lead to recurrence.... Why? because in question we are given [1, 2, 5]...
This works for me->
int equal(vector<int> arr) {
vector<int> possibilities(3);

// Start with the minimum element
int minimum = *min_element(arr.begin(), arr.end());

for (int i = 0; i < 3; i++) {

for (int k : arr) {
int diff = k - minimum;
int stepsRequired = diff / 5 + (diff % 5) / 2 + ((diff % 5) % 2) / 1;
possibilities[i] += stepsRequired;
}
minimum--;
}

// Return the minimum number out of all the possibilities
return *min_element(possibilities.begin(), possibilities.end());
}

sudarshanmaskare
Автор

Very nice bro 😃 Well explained & animation made it so easy
Thank You!!

tanishqmahendrasaini
Автор

My first thought was solving this through BFS

artistic__
Автор

your explanation was great, it really helped me

vtmcedxc
Автор

Bro, Thanks a lot, finally understood the solution <3

praveenmani
Автор

voice(not so quick not so slow moderate)& explanation are on 🔥

codinghouse
Автор

i don't understand why only till min-4 is considered

sculptandstyle_
Автор

Heya, I'm still confused about min to min-4.

rajeshpaithari
Автор

Please explain more about the optimal solution being present in [min, min-4] range

PIYUSH
Автор

when we reach min-5 then how it will be same scenario ??(14:02)

BestOption
Автор

bruh i have a doubt what if min=2, then will the still continue till it calculates min-4

shwetaravi
Автор

how you come to know that min will go till min-4??

vijaykumarsingh
Автор

14:05 can someone please explain to me how is (minimum - 5) the same scenario??

doremifasolatee
Автор

according to algorith ans to 1 5 5 is 4 but the true ans is 3

uttamkumarreddygaggenapall