Solving Tesla's 2020 Most Asked Interview Question

แชร์
ฝัง
  • เผยแพร่เมื่อ 6 ส.ค. 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
  • วิทยาศาสตร์และเทคโนโลยี

ความคิดเห็น • 36

  • @webdeveloper2432
    @webdeveloper2432 7 หลายเดือนก่อน +4

    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 3 ปีที่แล้ว +4

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

  • @SPMenOfficial
    @SPMenOfficial 3 ปีที่แล้ว +1

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

  • @jemschaudhary5922
    @jemschaudhary5922 3 ปีที่แล้ว

    Nicely Described...Thank you

  • @heisenberg1844
    @heisenberg1844 3 ปีที่แล้ว

    Thanks. Awesome as always

  • @TSAMikeyo89
    @TSAMikeyo89 2 ปีที่แล้ว +1

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

  • @arnabchakraborty246
    @arnabchakraborty246 3 ปีที่แล้ว

    Great sir ,Thank you very much sir

  • @cbjueueiwyru7472
    @cbjueueiwyru7472 3 ปีที่แล้ว +9

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

  • @codestorywithMIK
    @codestorywithMIK 3 ปีที่แล้ว +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 💡

    • @AlgosWithMichael
      @AlgosWithMichael  3 ปีที่แล้ว +1

      Haha I'm glad you like the format. Thank you for watching, more videos to come!

    • @codestorywithMIK
      @codestorywithMIK 3 ปีที่แล้ว

      @@AlgosWithMichael 👍

  • @samikshadharmadhikari1583
    @samikshadharmadhikari1583 3 ปีที่แล้ว

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

  • @cadbury358
    @cadbury358 3 ปีที่แล้ว

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

  • @Bandz-rl3qk
    @Bandz-rl3qk 3 ปีที่แล้ว

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

    • @AlgosWithMichael
      @AlgosWithMichael  3 ปีที่แล้ว +1

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

  • @randommindz6782
    @randommindz6782 2 ปีที่แล้ว

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

  • @angelsancheese
    @angelsancheese 2 ปีที่แล้ว

    Thanks man

  • @sabertoothwallaby2937
    @sabertoothwallaby2937 3 ปีที่แล้ว +1

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

    • @AlgosWithMichael
      @AlgosWithMichael  3 ปีที่แล้ว

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

  • @henri0515
    @henri0515 2 ปีที่แล้ว

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

  • @tomladdus9264
    @tomladdus9264 3 ปีที่แล้ว

    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  3 ปีที่แล้ว

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

  • @N00BRIUM
    @N00BRIUM ปีที่แล้ว

    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
    ])

  • @championsofodin9868
    @championsofodin9868 2 ปีที่แล้ว

    Bro I don’t even understand the question haha

  • @henrifritsmaarseveen6260
    @henrifritsmaarseveen6260 2 ปีที่แล้ว

    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"
    .