filmov
tv
Solving Tesla's 2020 Most Asked Interview Question
Показать описание
Check out my interview prep platform for learning the patterns!
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
Комментарии