Greedy Algorithms Tutorial – Solve Coding Challenges



Learn how to use greedy algorithms to solve coding challenges. Many tech companies want people to solve coding challenges during interviews and many of the challenges can be solved using a greedy algorithm. A greedy algorithm is any algorithm that follows the problem-solving heuristic of making the locally optimal choice at each stage.

✏️ Course from Tanishq Chaudhary. Check out his channel: https://www.youtube.com/c/TanishqChaudhary1337/

Links to coding challenges on InterviewBit:
🔗 Highest product: https://www.interviewbit.com/problems/highest-product/
🔗 Bulbs: https://www.interviewbit.com/problems/interview-questions/
🔗 Disjoint intervals: https://www.interviewbit.com/problems/disjoint-intervals/
🔗 Largest permutation: https://www.interviewbit.com/problems/largest-permutation/
🔗 Meeting rooms: https://www.interviewbit.com/problems/meeting-rooms/
🔗 Distribute candy: https://www.interviewbit.com/problems/distribute-candy/
🔗 Seats: https://www.interviewbit.com/problems/seats/
🔗 Assign mice to holes: https://www.interviewbit.com/problems/assign-mice-to-holes/
🔗 Majority element: https://www.interviewbit.com/problems/majority-element/
🔗 Gas station: https://www.interviewbit.com/problems/gas-station/

⭐️ Course contents ⭐️
⌨️ (0:00:00) Greedy introduction
⌨️ (0:04:32) Bulbs
⌨️ (0:12:11) Highest product
⌨️ (0:17:08) Disjoint intervals
⌨️ (0:28:43) Largest permutation
⌨️ (0:38:30) Meeting rooms
⌨️ (0:49:25) Distribute candy
⌨️ (1:03:13) Seats
⌨️ (1:19:13) Assign mice to holes
⌨️ (1:24:19) Majority element
⌨️ (1:35:28) Gas station
⌨️ (1:52:39) End

🎉 Thanks to our Champion and Sponsor supporters:
👾 Raymond Odero
👾 Agustín Kussrow
👾 aldo ferretti
👾 Otis Morgan
👾 DeezMaster

Learn to code for free and get a developer job: https://www.freecodecamp.org

Read hundreds of articles on programming: https://freecodecamp.org/news

source

This Post Has 34 Comments

  1. Hey everyone!
    I am Tanishq Chaudhary, the creator of this mini-course on greedy algorithms.

    Just want to say … big thanks to Beau for giving me this opportunity💖
    It is a pleasure to share high quality content with the freeCodeCamp audience and contribute back to the community 🙏

    You check out YouTube channel, where I have tons of videos like this already (with many more coming soon!): https://www.youtube.com/c/TanishqChaudhary1337/

    You can also follow me on LinkedIn: https://www.linkedin.com/in/tanishqchaudhary1337/

    Thanks,
    chaudhary1337

  2. Pratik Mhatre

    Thank you so much for your efforts. And thanx Beau for posting such useful content on this channel

  3. Garv Goel

    Hie @tanishq…. Loved the style of your coding. Learnt a lot from your coding style. Thank you❤

  4. Chris Vin

    the majority element solution blew my mind

  5. BlackRaven

    Is there another explanation of the bulbs problem? As in those classic CS problems like the Stable Marriage (Gale-Shapely)?

  6. Abidur Rahman

    When an Indian speaks English, it seems like he's speaking hindi.

  7. I can't wrap my head around "crosses = [(cross-index) for index,cross in enumerate(crosses)]" this part of the Seats problem. Any insights?

  8. sharad singh

    Wow, so well done! Thanks for posting, man! Very helpful.

  9. For maximum product problem, consider input as [-1,-2,-4,-3,0], both the hypothesis would be 0 and max would again be 0, interesting.

  10. King Maker

    In gas station question, you can avoid extra iteration like keeping condition
    if start>=n:
    break
    Thanks for the amazing tutorial 👍

  11. Karljuhaa

    Wow…….That' s so cool. Keep going Sir. TNice tutorials motivtes too.

  12. HK OMSI 2

    Jefferson Sales done a few but not there yet

  13. brian malone

    The bulb solution is remarkably unintuitive. Consider the bulbs in groups of similar values (e.g., 1111000 requires one flip; 000000011111 requires two; strict alternation is the worst case, as in 010101010). Then it's obvious you need to locate the first 0, then count the number of cases where a value differs from the preceding. It makes the solution provided by Sheyteo simple to understand, and avoids all the unnecessary modulo operations in the solution provided.

  14. What amazing solutions for all the videos !!! especially for majority element. When you need space o(1) just use bits..wow will always keep this is mind. Thank you 🙏

  15. PurePower

    That's it and no more cartoon network or Netflix or burger king.

  16. Axio

    '… add a vst like a setup' * H E A V Y B R E A T H I N G *

  17. j

    As far as i know, the FIRST tNice tutorialng We should do is SET THE TEMPO, it is very crucial.

Leave a Reply