Solving Amazon's 2020 Most Asked Interview Question
Вставка
- Опубліковано 6 лют 2025
- 🎧 Join the community Discord: / discord
💰 Support me on Patreon: / michaelmuinos
🔗Follow me on LinkedIn: / michael-muinos
📂Follow me on Github: github.com/Mic...
Check out my interview prep platform for learning the patterns!
📢 Interview Prep Platform: algoswithmicha...
Amazon's most asked coding question for 2020 according to the LeetCode platform was "Reorder Data in Log Files". This problem is a string based problem which in just the past 6 months has been asked at Amazon over 330 times.
For this problem, we must sort log strings based on a variety of rules. There are two types of log strings: letter logs and digit logs. Letter logs contain a unique id separated with a space to the rest of the log portion. The log portion contains only lowercase letters; however, a digit log contains only digits. The rules we must implement our comparator class by are as follows:
letter logs always come before digit logs, letter logs are sorted lexicographically, if letter logs are equal we must sort by the id lexicographically, and digit logs should maintain their order.
The time complexity for our algorithm is big oh O(N*log(N)) where N is the number of elements we have in our array. Under the hood, the array sort uses a dual pivot quick sort algorithm which is due to the use of sorting primitives. If we were not sorting primitives, the sort function would use TimSort. The space complexity is big oh O(log(N)) since quick sort must utilize recursive calls to apply sorting.
----------------------------------------------------
LAKEY INSPIRED - Blue Boi
/ lakeyinspired
/ @lakeyinspired
Love the visual animations. This can be USP of your channel. Keep it up!!
I like your video series on frequently asked question on amazon,google.. etc.. and the best part of it is you replay to everyone for there doubts..keep it up good work..
btw you can use string.split(" ", 2) to divide a log in to the id and the main part so you dont have to find the first occurence of a space and then use substring.
This may exclude additional parts of the log in some languages
i may be being repetitive here but i love the visual explanations.. just saw your vids first time and subscribing! keep up the good quality content!
I'm glad, I like doing in depth animations
Great explanation. One thing to keep in mind while implementing the algorithm in a language other than Java is that returning 0 does not guarantee the stable order. One might need to research other sorting facilities to satisfy the digital logs order rule.
Very good point
Me getting more frustrated after writing a 200 line code and wasting 3 hours on this problem only to see your efficient solution and completely different approach !!! Just wow
I got a similar question to this last month for my first round at Amazon. Although it was slightly different
love the new visuals during explanation. Keep up the great work!
Thanks so much!
thanks a lot bro. Wishing your channel for rapid growth
I appreciate that, thank you for watching!
Great explanation !! Im trying to figure out the -1 part can someone help return digit1 ? (digit2? 0 : 1) : -1;
-1 will be executed when digit1 is a letter log(not a digit log) then why do we want to return -1?
Nice video. Keep up the good work!
Thank you!
your videos are seriously amazing!!! 👏🏿👏🏿👏🏿👏🏿
Thank you so much 😀
Fantastic video. Really helped understand how to use comparator
Glad you enjoyed it!
Hi Michael, what I can't understand is if(isDigit1 && isDigit2) return 0; why do we return 0 if they are both digit.
@@joshualopes7250 ....which only works in Java. In C# it changes the ordering, for example.
This is gold! Keep it up!
Thanks, will do!
Really appreciate your work! thanks a lot!
My pleasure!
Very clean solution!
Thank you, I think so too :p
@8:44 WTF lol..BTW great solution thank you for sharing
LOL thanks dude!
could u share the leetcode link for this problem?
Search on LeetCode "Reorder data in log files" and you should find it
Woooooo life saver thank you
awesome Explanation....
Glad you liked it!
thats a beautiful hat, just subscribed
Nothing compared to that beard
Love your work. If I paid ya, could you do a private lesson? DM me if so
I appreciate that! I don't do private lessons currently :(