Advanced Greedy

Huffman coding for compression, string rearrangement, and other advanced greedy applications.

37 lessons
87 min
Codeforces: 1400-2000LeetCode: 1500-2000

Lessons

1. Intro

Beyond basic greedy

2m

2. Problem - Huffman Coding

Optimal prefix codes

3m1 problems

3. Huffman - Algorithm

Build the tree

4m

4. Huffman - Implementation

The code

3m1 problems

5. Problem - Reorganize String

No adjacent duplicates

3m1 problems

6. Reorganize String - Algorithm

Max-heap approach

3m

7. Reorganize String - Implementation

The code

3m1 problems

8. Quiz: Reorganize String

Feasibility check

1m1 problems

9. Problem - Remove K Digits

Minimize the number

3m1 problems

10. Remove K Digits - Algorithm

Stack-based greedy

3m

11. Remove K Digits - Implementation

The code

3m1 problems

12. Remove K Digits - Why Greedy

Local removal helps globally

2m

13. Quiz: Remove K Digits

Understanding the stack

1m1 problems

14. Problem - Create Maximum Number

Merge two arrays

2m1 problems

15. Create Maximum - Subproblems

Three greedy steps

3m

16. Create Maximum - Max from One Array

Monotonic stack selection

3m

17. Create Maximum - Merge Step

Lexicographic comparison

3m

18. Create Maximum - Full Solution

Putting it together

3m1 problems

19. Problem - Patching Array

Cover all sums

2m1 problems

20. Patching Array - The Idea

Extend the range

3m

21. Patching Array - Implementation

The code

3m1 problems

22. Quiz: Patching Array

Why add miss

1m1 problems

23. Problem - Candy Crush

Eliminate matches

2m1 problems

24. Candy Crush - Algorithm

Mark, crush, drop

2m

25. Candy Crush - Implementation

The code

3m1 problems

26. Problem - Minimum Number of Arrows

Burst all balloons

2m1 problems

27. Arrows - Greedy Insight

Activity selection variant

2m

28. Arrows - Implementation

The code

2m1 problems

29. Quiz: Arrows vs Activity Selection

Spotting the connection

1m1 problems

30. Problem - Minimum Increment to Make Array Unique

No duplicates

2m1 problems

31. Make Unique - Greedy Approach

Sort and fix

2m

32. Make Unique - Implementation

The code

2m1 problems

33. Advanced Greedy Patterns

Common themes

3m

34. When Greedy Gets Tricky

Pitfalls to watch

2m

35. Quiz: Advanced Greedy

Choosing the right approach

1m1 problems

36. What is Next

Practice section

2m

37. Section Recap

What we learned

2m

Practice Problems

1.
Priority Queuecodeforces
3.
Minimum Pathcodeforces
4.
Buds Re-hangingcodeforces
5.
7.

Ready to start learning?

Access all 37 lessons with interactive content and progress tracking.