Solving Tesla's 2020 Most Asked Interview Question

Sdílet
Vložit
  • čas přidán 6. 08. 2020
  • 🎧 Join the community Discord: / discord
    💰 Support me on Patreon: / michaelmuinos
    🔗Follow me on LinkedIn: / michael-muinos
    📂Follow me on Github: github.com/MichaelMuinos
    Check out my interview prep platform for learning the patterns!
    📢 Interview Prep Platform: algoswithmichael.com
    In this video, I go over a full solution for solving Tesla's most commonly asked interview coding question in 2020. The problem is called "Maximum Number of Balloons" and was found on the LeetCode platform.
    For this problem, we need to find the max number of "balloon" words we can create by just using the letters in our input string. To solve this, we need to get a count of all characters in our string. We could use a HashMap data structure to do this; however, a better way is to have an integer array of size 26. We use 26 because our input will always only be lowercase letters. Each index will map to a unique lowercase letter starting with lowercase 'a' at index 0.
    With these counts, we calculate the minimum count at the indices containing the characters 'b', 'a', 'l', 'o', and 'n'. We use these characters because those are what make up the word "balloon".
    Our time complexity is going to be big oh N where N is the number of character in our input string. Our space complexity is going to be constant -- since the array we initialize will always be of size 26, it won't add extra memory.
    ----------------------------------------------------
    Better Days by Lakey Inspired
    / lakeyinspired
    / @lakeyinspired
  • Věda a technologie

Komentáře • 36

  • @webdeveloper2432
    @webdeveloper2432 Před 9 měsíci +5

    I think we can have an integer of size 5. Our only interest is in the letter 'b','a','l','o','n'. We can ignore the other ones and do the min on that array.

  • @yousufbaig
    @yousufbaig Před 4 lety +4

    Awesome simple solution.
    A good approach. Enjoyed the video!
    Stay safe!

  • @SPMenOfficial
    @SPMenOfficial Před 3 lety +1

    so brilliant! what an easier method to use! tq so much 👍🏻

  • @jemschaudhary5922
    @jemschaudhary5922 Před 3 lety

    Nicely Described...Thank you

  • @heisenberg1844
    @heisenberg1844 Před 4 lety

    Thanks. Awesome as always

  • @TSAMikeyo89
    @TSAMikeyo89 Před 2 lety +1

    i can’t believe i knew the answer outright for a Tesla question 😱

  • @arnabchakraborty246
    @arnabchakraborty246 Před 3 lety

    Great sir ,Thank you very much sir

  • @cbjueueiwyru7472
    @cbjueueiwyru7472 Před 3 lety +9

    Teslas most asked question..... "You cool with panel gaps?"

  • @samikshadharmadhikari1583

    Hey can you add some more videos in this playlist. TIA

  • @codestorywithMIK
    @codestorywithMIK Před 4 lety +3

    Why you are too good ?
    1) you talk first about approach in a pretty easy way
    2) MOST IMPORTANT, you explain the TIME COMPLEXITY 💡

  • @cadbury358
    @cadbury358 Před 3 lety

    here count array can't be initialized
    what are the initial values in count

  • @Bandz-rl3qk
    @Bandz-rl3qk Před 3 lety

    if your dividing by 2 shouldnt it log n base 2?

    • @AlgosWithMichael
      @AlgosWithMichael  Před 3 lety +1

      The division portion takes constant time, but looping over all characters is going to take linear time.

  • @angelsancheese
    @angelsancheese Před 2 lety

    Thanks man

  • @randommindz6782
    @randommindz6782 Před 3 lety

    I am mad on the premise I would've done something longer than this....
    This is why I prefer Object-Oriented programming over algorithms!

  • @henri0515
    @henri0515 Před 2 lety

    Jesus... I switching from c# to c++

  • @sabertoothwallaby2937
    @sabertoothwallaby2937 Před 3 lety +1

    what languages should I learn!?!!?!?!? I have HTML, CSS, JS, SQL, React

    • @AlgosWithMichael
      @AlgosWithMichael  Před 3 lety

      Learn any languages you are interested in learning. Can't go wrong with Python though, lots of things you can do with it

  • @tomladdus9264
    @tomladdus9264 Před 4 lety

    My approach the map approach, should work for any input unicode string, should still be order N, although not quite as efficient as doing math. in Swift, it is not as simple to map to ascii:
    func maxNumberOfBalloons(_ text: String) -> Int {
    let balloon = "balloon"
    var chars: [Character: Int] = [:]
    for char in text {
    if balloon.contains(char) {
    chars[char, default: 0] += 1
    }
    }
    var count = 0
    while true {
    for char in balloon {
    if chars[char, default: 0] == 0 {
    return count
    }
    chars[char, default: 0] -= 1
    }
    count += 1
    }
    return count
    }

    • @AlgosWithMichael
      @AlgosWithMichael  Před 4 lety

      Yep, map approach is just fine! Both ways to solve it have the same time / space.

  • @championsofodin9868
    @championsofodin9868 Před 2 lety

    Bro I don’t even understand the question haha

  • @henrifritsmaarseveen6260

    read the question again
    it tells you , you can only use once the chars in text
    so when you count them .. you already used them once! !
    it doesn't tell you "use once to form the word balloon" . so I assume use once to process the data "text"
    .

  • @N00BRIUM
    @N00BRIUM Před rokem

    Here's an easy solution in Python3 which is generic (not restricted to just balloons).
    from collections import Counter
    class Solution:
    def maxNumberOfBalloons(self, text: str) -> int:
    return self.max_number_of_subtext(text, "balloon")
    def max_number_of_subtext(self, text: str, subtext: str) -> int:
    text_counter = Counter(text)
    subtext_counter = Counter(subtext)
    return min([
    text_counter[ch]//subtext_counter[ch] for ch in subtext
    ])