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

КОМЕНТАРІ • 41

  • @sagardafle
    @sagardafle 2 роки тому

    Love the visual animations. This can be USP of your channel. Keep it up!!

  • @leenaverma2418
    @leenaverma2418 3 роки тому +1

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

  • @solomoon4784
    @solomoon4784 2 роки тому +1

    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.

    • @firstburrito
      @firstburrito 2 роки тому +1

      This may exclude additional parts of the log in some languages

  • @atift5465
    @atift5465 4 роки тому +2

    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!

  • @sergten
    @sergten 4 роки тому +2

    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.

  • @manojpatil7351
    @manojpatil7351 3 роки тому +1

    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

  • @Soccerguyz
    @Soccerguyz 8 місяців тому

    I got a similar question to this last month for my first round at Amazon. Although it was slightly different

  • @pl5778
    @pl5778 4 роки тому

    love the new visuals during explanation. Keep up the great work!

  • @balaeinstein8710
    @balaeinstein8710 4 роки тому +1

    thanks a lot bro. Wishing your channel for rapid growth

  • @z4zebraa
    @z4zebraa 3 роки тому

    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?

  • @urbirooj5413
    @urbirooj5413 4 роки тому +1

    Nice video. Keep up the good work!

  • @MayaBello
    @MayaBello 4 роки тому

    your videos are seriously amazing!!! 👏🏿👏🏿👏🏿👏🏿

  • @MangoDrankE
    @MangoDrankE 4 роки тому

    Fantastic video. Really helped understand how to use comparator

  • @yitingg7942
    @yitingg7942 3 роки тому +1

    Hi Michael, what I can't understand is if(isDigit1 && isDigit2) return 0; why do we return 0 if they are both digit.

    • @Hadi4029
      @Hadi4029 2 роки тому

      @@joshualopes7250 ....which only works in Java. In C# it changes the ordering, for example.

  • @seriouslyIamnobody
    @seriouslyIamnobody 4 роки тому

    This is gold! Keep it up!

  • @SarveshKumar-nh3pd
    @SarveshKumar-nh3pd 4 роки тому

    Really appreciate your work! thanks a lot!

  • @Play-Date-Care
    @Play-Date-Care 4 роки тому

    Very clean solution!

  • @nribackpacker
    @nribackpacker 4 роки тому +1

    @8:44 WTF lol..BTW great solution thank you for sharing

  • @SunilGupta-vc8jw
    @SunilGupta-vc8jw 4 роки тому +1

    could u share the leetcode link for this problem?

    • @AlgosWithMichael
      @AlgosWithMichael  4 роки тому +1

      Search on LeetCode "Reorder data in log files" and you should find it

  • @z41n70
    @z41n70 3 роки тому

    Woooooo life saver thank you

  • @neetibhatt3983
    @neetibhatt3983 4 роки тому

    awesome Explanation....

  • @TheTsarSniper
    @TheTsarSniper 4 роки тому

    thats a beautiful hat, just subscribed

  • @DrJavyMartinez
    @DrJavyMartinez 3 роки тому

    Love your work. If I paid ya, could you do a private lesson? DM me if so

    • @AlgosWithMichael
      @AlgosWithMichael  3 роки тому

      I appreciate that! I don't do private lessons currently :(