Solving Tesla's 2020 Most Asked Interview Question

  Рет қаралды 25,450

AlgosWithMichael

AlgosWithMichael

3 жыл бұрын

🎧 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 9 ай бұрын
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 жыл бұрын
Awesome simple solution. A good approach. Enjoyed the video! Stay safe!
@AlgosWithMichael
@AlgosWithMichael 3 жыл бұрын
Thank you, same to you!
@TSAMikeyo89
@TSAMikeyo89 2 жыл бұрын
i can’t believe i knew the answer outright for a Tesla question 😱
@SPMenOfficial
@SPMenOfficial 3 жыл бұрын
so brilliant! what an easier method to use! tq so much 👍🏻
@SPMenOfficial
@SPMenOfficial 3 жыл бұрын
so understandable!
@heisenberg1844
@heisenberg1844 3 жыл бұрын
Thanks. Awesome as always
@AlgosWithMichael
@AlgosWithMichael 3 жыл бұрын
No problem 👍
@jemschaudhary5922
@jemschaudhary5922 3 жыл бұрын
Nicely Described...Thank you
@AlgosWithMichael
@AlgosWithMichael 3 жыл бұрын
You're most welcome
@cbjueueiwyru7472
@cbjueueiwyru7472 3 жыл бұрын
Teslas most asked question..... "You cool with panel gaps?"
@AlgosWithMichael
@AlgosWithMichael 3 жыл бұрын
LOL
@arnabchakraborty246
@arnabchakraborty246 3 жыл бұрын
Great sir ,Thank you very much sir
@AlgosWithMichael
@AlgosWithMichael 3 жыл бұрын
Anytime!
@codestorywithMIK
@codestorywithMIK 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 жыл бұрын
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
@AlgosWithMichael
@AlgosWithMichael 3 жыл бұрын
Definitely
@Bandz-rl3qk
@Bandz-rl3qk 3 жыл бұрын
if your dividing by 2 shouldnt it log n base 2?
@AlgosWithMichael
@AlgosWithMichael 3 жыл бұрын
The division portion takes constant time, but looping over all characters is going to take linear time.
@cadbury358
@cadbury358 3 жыл бұрын
here count array can't be initialized what are the initial values in count
@clivedsouza6213
@clivedsouza6213 3 жыл бұрын
zeros
@randommindz6782
@randommindz6782 3 жыл бұрын
I am mad on the premise I would've done something longer than this.... This is why I prefer Object-Oriented programming over algorithms!
@AlgosWithMichael
@AlgosWithMichael 3 жыл бұрын
Haha relatable
@angelsancheese
@angelsancheese 2 жыл бұрын
Thanks man
@AlgosWithMichael
@AlgosWithMichael 2 жыл бұрын
No prob!
@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.
@henri0515
@henri0515 2 жыл бұрын
Jesus... I switching from c# to c++
@sabertoothwallaby2937
@sabertoothwallaby2937 3 жыл бұрын
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
@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" .
@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 ])
Solving Amazon's 2020 Most Asked Interview Question
9:57
AlgosWithMichael
Рет қаралды 17 М.
Amazon Coding Interview Question - Integer to Roman (LeetCode)
9:06
AlgosWithMichael
Рет қаралды 20 М.
NERF WAR HEAVY: Drone Battle!
00:30
MacDannyGun
Рет қаралды 42 МЛН
Please be kind🙏
00:34
ISSEI / いっせい
Рет қаралды 192 МЛН
ИРИНА КАЙРАТОВНА - АЙДАХАР (БЕКА) [MV]
02:51
ГОСТ ENTERTAINMENT
Рет қаралды 10 МЛН
Must-have gadget for every toilet! 🤩 #gadget
00:27
GiGaZoom
Рет қаралды 12 МЛН
Ex-Google Software Engineer Speeds Through 3 Coding Interview Problems
59:23
Clément Mihailescu
Рет қаралды 102 М.
Trie Data Structure Implementation (LeetCode)
11:50
AlgosWithMichael
Рет қаралды 70 М.
Top K Frequent Words - Priority Queue Approach (LeetCode)
13:26
AlgosWithMichael
Рет қаралды 34 М.
My Experience Working as a Tesla Engineer
9:52
Tamer Shaheen
Рет қаралды 649 М.
13 Questions Tesla asks in 98% of Interviews (SpaceX too)
26:11
Dan Croitor
Рет қаралды 10 М.
Google Coding Question - Making a Large Island (Hard)
25:11
AlgosWithMichael
Рет қаралды 15 М.
Hardest Coding Problem Explained (LeetCode)
16:47
AlgosWithMichael
Рет қаралды 11 М.
SWE Internship Interview Process FULLY Explained
15:12
Allen Ye
Рет қаралды 3,2 М.
5 Data Structures Explained MUST KNOW (for Software Engineers)
10:15
AlgosWithMichael
Рет қаралды 8 М.
Stock Price Fluctuation - Google Coding Interview Question
15:11
AlgosWithMichael
Рет қаралды 510
После ввода кода - протирайте панель
0:18
Up Your Brains
Рет қаралды 1 МЛН
Собери ПК и Получи 10,000₽
1:00
build monsters
Рет қаралды 2,1 МЛН