Inverting Binary Trees - You Suck at Coding [1]

Поділитися
Вставка
  • Опубліковано 21 січ 2021
  • Inverting binary trees is not as scary as it sounds.
    #benawad #coding #faang ​

    ----
    Follow me online: voidpet.com/benawad
    #benawad
  • Наука та технологія

КОМЕНТАРІ • 844

  • @paul4ashraf
    @paul4ashraf 3 роки тому +3232

    Not gonna lie I was actually impressed when you inverted the whole google doc

  • @amanmathur_
    @amanmathur_ 3 роки тому +1816

    Some poor kid is gonna watch this and recite it in an interview.

    • @pguti778
      @pguti778 3 роки тому +16

      I'll do!!!!

    • @karanparmar4318
      @karanparmar4318 3 роки тому +30

      I was planning to -

    • @greatbullet7372
      @greatbullet7372 3 роки тому +7

      the show must go on ^^

    • @facundofrosoni6687
      @facundofrosoni6687 3 роки тому +99

      I had to come to the comments because until 2:34 I didn't even suspect. But when he came up with "the programming language I like to start with is CSS", I said "fk I'm really lost or this guy's trolling me"

    • @phoneix24886
      @phoneix24886 3 роки тому +5

      Shouldn't I? I thought the bird imitation could get me the job

  • @erwinschrodinger2320
    @erwinschrodinger2320 3 роки тому +2144

    Alt F4 to open dev mode, a yes a professional.

    • @oliverchen4079
      @oliverchen4079 3 роки тому +37

      I almost fell for it

    • @oliverchen4079
      @oliverchen4079 3 роки тому +8

      Ctrl. Shift I or F12 or Ctrl. Shift J bruh

    • @31redorange08
      @31redorange08 3 роки тому +52

      It actually closed the browser window for me.

    • @josephcagle
      @josephcagle 3 роки тому +18

      Joke's on you. That didn't get me because I'm on a Mac.

    • @vincentadeniji6403
      @vincentadeniji6403 3 роки тому +9

      @@31redorange08 yeah, that's what it's suppose to do rofl.

  • @clem
    @clem 3 роки тому +2755

    I was going to give you a *Hire* decision, but the bird imitation at the end convinced me that this was worthy of a *Strong Hire*

  • @kenjopac4247
    @kenjopac4247 3 роки тому +859

    I died at "The language I like to start with is CSS"

    • @JaycenGiga
      @JaycenGiga 3 роки тому +22

      Well, CSS *is* Turing complete, soo …

    • @greatbullet7372
      @greatbullet7372 3 роки тому +2

      @@JaycenGiga its dependant too..

    • @monad_tcp
      @monad_tcp 3 роки тому +7

      well, CSS is a language

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

      Hahahahahhaa same 😂😂😂

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

      @@monad_tcp HTML too. It's in the name Hyper Text Markup Language

  • @dbtechprojects2392
    @dbtechprojects2392 3 роки тому +1338

    "This is bound to make you stand out ..... !important" I'm dying

    • @artinmajidi1654
      @artinmajidi1654 3 роки тому +56

      In case anyone doesn´t understand, the important value means how it´s code is prioritized (in some cases properties collide). ! important means not important, so nothing will happen.
      (Apparently people don't get a joke)

    • @AsifIqbalR
      @AsifIqbalR 3 роки тому +20

      @@artinmajidi1654 are you on crack?

    • @k00p28
      @k00p28 3 роки тому +7

      @@artinmajidi1654 I'm pretty sure you are confused and confusing other dude

    • @rewrittenbytes1616
      @rewrittenbytes1616 3 роки тому +29

      artin majidi tf? at least know what you’re talking about before you try to educate someone on something lmao
      !important is a css property which gives the attribute it’s used upon the highest precedence
      so basically the joke is if you use !important you’ll always have the highest priority
      given the context of the joke (he was literally using css) we can safely assume he was talking about the !important attribute in css, instead of using ! as “not”

    • @user-un7lc4uy9b
      @user-un7lc4uy9b 3 роки тому +5

      @@artinmajidi1654 !important means a lot , !importat means important, u should study css to understand it, simply it makes the code stronger so the system will do it (because it is important), i advise u not to depend on it all the time or your project will fail.

  • @gaxxey4300
    @gaxxey4300 3 роки тому +581

    4:38 please show the youtube stats on how many people "clicked off" the video at this point

  • @tejas3269
    @tejas3269 3 роки тому +444

    Every time I hear :
    Do you want to be software engineer at Google
    I mute sound so that my friends can't laugh at me

    • @Bebs_
      @Bebs_ 3 роки тому +43

      gO To aLgO expert dot CoMm

    • @safwanljd
      @safwanljd 3 роки тому +14

      @@Bebs_ dot io*

    • @DragonRazor9283
      @DragonRazor9283 3 роки тому +14

      gEt StUcK?

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

      Lmfao

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

      @@DragonRazor9283 sTeP bRo! *Is your way to go*

  • @himbeerme
    @himbeerme 3 роки тому +141

    "They're like begging to be inverted or something." lmao

    • @Unreadable69
      @Unreadable69 3 роки тому +2

      I actually laughed so hard when I heard that haha

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

      @@Unreadable69 I also laughed out loud

  • @StevenCastellucci
    @StevenCastellucci 3 роки тому +145

    I don't know what's more impressive -- your coding skills, or your ability to keep a straight face while giving "advice" :D

  • @simonthor7593
    @simonthor7593 3 роки тому +665

    In Python, you can actually do
    node.left, node.right = node.right, node.left
    and skip the temporary variable

    • @samuelgunter
      @samuelgunter 3 роки тому +78

      same with JavaScript, except you have to say [var2, var1] = [var1, var2]
      (replace var1 and var2 with 2 variables)

    • @brianevans4
      @brianevans4 3 роки тому +10

      @@samuelgunter thats the cleanest array swap

    • @iDraKzy
      @iDraKzy 3 роки тому +90

      @@samuelgunter And if the data is a number and you wanna be a fancy ass you can use the mathematical method:
      var1 = var1 + var2
      var2 = var1 - var2
      var1 = var1 - var2
      And just like that it's inverted :D

    • @samuelgunter
      @samuelgunter 3 роки тому +28

      @@iDraKzy well yeah if you want to use extra lines and make it unclear :p

    • @iDraKzy
      @iDraKzy 3 роки тому +8

      @@samuelgunter Or if you use another language than python or javascript ;p

  • @KarimShalapy
    @KarimShalapy 3 роки тому +114

    Did y'all hear Ben imitate the birds' sound? He's secretly a bird that hates how trees look and his sole purpose in life is to invert 'em all!

  • @satvikreddy8662
    @satvikreddy8662 3 роки тому +75

    **at a faang interview**
    Interviewer: I would like you to perform the chacha slide on a binary octopus.
    Ben: You know I hold the world record fastest binary octopus chacha slide right?

  • @thatguyoverthere1648
    @thatguyoverthere1648 3 роки тому +206

    8:25 Bruh. “I’m getting a compile error” in google docs, and in python, an interpreted language😂😂

    • @_trbr
      @_trbr 3 роки тому +29

      Are you implying that Ben made a mistake here? Don't be ridiculous, he's a haskell chad - he wouldn't ever make a mistake

    • @thatguyoverthere1648
      @thatguyoverthere1648 3 роки тому +11

      Oh, of course, I forgot about the new pep, which allows you to compile in google docs, ben couldn’t be wrong

  • @ahuman32478
    @ahuman32478 Рік тому +8

    I came back to this video to thank you. A week ago, I applied to an entry-level python job and I managed to land an interview with the company. They asked me the classic questions like "What are your weaknesses", etc, and I was bombing so hard because I wasn't confident. But then, the magical moment came. They asked me to plan out a program to invert a binary tree on a whiteboard. Thankfully, I watched this video and was able to complete the task flawlessly. The recruiter was so impressed that he recommended that I work in a senior position instead of an entry-level one. Long story short, I ended up becoming the youngest CEO of a Fortune 500 company. Thank you, Ben Awad!

    • @aerohk
      @aerohk Рік тому +5

      Fortune 500? That's a nice word for non-FAANG companies. Not impressed, try harder.

  • @akshitkumar9402
    @akshitkumar9402 3 роки тому +35

    6:55 should be 10 spaces
    Failed the interview like a chad

  • @saideepesh6036
    @saideepesh6036 3 роки тому +78

    9:54 when you're using Angular in front of Ben Awad

  • @mo99
    @mo99 3 роки тому +261

    "Google: 90% of our engineers use the software you wrote (Homebrew), but you can’t invert a binary tree on a whiteboard so fuck off." - Max Howell, creator of Homebrew

  • @aaronmarsh8
    @aaronmarsh8 3 роки тому +213

    Glad to see the Angular jokes are back 😃😂

  • @DessertRatt
    @DessertRatt 3 роки тому +20

    "18 font so we can actually see what we're doing"
    Someone get this man a medal for this level of comedy

  • @amanrubey
    @amanrubey 3 роки тому +32

    this cracked me up " whenever u look at binary tree it already looks inverted"🤣🤣🤣

  • @SuboptimalEng
    @SuboptimalEng 3 роки тому +219

    *Ben Awad Exists*
    Angular: 👁👄👁

    • @sainathsingineedi2922
      @sainathsingineedi2922 3 роки тому +4

      Hi suboptimal

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

      @@sainathsingineedi2922 so we meet again 😂

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

      angularJS*, cuz angular is a different framework ;)

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

      @@AnimusAgent That always confuses me. Which one is he talking about? He should surely know angular 2.0+ is angular and not angularjs right?

  • @nskybytskyi
    @nskybytskyi 3 роки тому +26

    def InvertTree(node):
    if node:
    node.left, node.right = InvertTree(node.right), InvertTree(node.left)
    return node
    If you use python then why not unleash its true power?
    // with std::tie and std::make_pair, the same thing is possible in C++

  • @rishabhscodes
    @rishabhscodes 3 роки тому +67

    F (for the microsoft interns who bring users to VSCode by making extensions)

    • @Enroxxx
      @Enroxxx 3 роки тому +5

      btw, they get paid, pretty well.

  • @memespdf
    @memespdf 3 роки тому +61

    8:45
    If you want to impress your interviewer, you can use the more pythonic way:
    node.left, node.right = node.right, node.left
    Note that this may also cause C++ developers to hang up on the spot so use with caution.

    • @hipstergod
      @hipstergod 3 роки тому +6

      yeah from interview experience(over 40 tech interviews) they much rather you keep to normal conventions and not take advantage of Pythonic shortcuts, youre showing you know the language but youre mossong out on proving the thing theyre looking for whoch is programmatic understanding of data structures/algos
      if you do this stuff always make sure to state to the interviewer whats happening behind the scenes

    • @doc8527
      @doc8527 3 роки тому +2

      @@hipstergod Exactly. It's a video for fun but I saw a lot of people are talking about those language shortcuts.
      I hate today's algo interview but a lot of people are indeed misunderstanding the "original purpose" of those questions.
      You can use those shortcut after explanation or show them the not shortcut version. They want to know your understanding of basic data structures/algos.
      Believe or not, a lot of people can do some fancy `filter()` `reduce()` functions to solve the problem with 1 line but don't know how to use a simple for loop to achieve the same thing. When you need to do some specific optimizations with your own for loop, this is the key why those questions are designed. Many terrible/slow apps have some filter(map()) like combination code to deal with some simple problem behind the scene, end up has O(n^2) - O(n^3) without concern.
      Unfortunately, 99% of algo questions are over complicated due to the markets, hot trends, salary, population, even H1B, etc. I believe the result of the bar rising is a complex problem behind the industry.

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

      @@doc8527 yyeeess, I use Python for my interviews. its my first language and perfect for interviews but using Pythonic shortcuts are so much cancerrr. I hate going to leet code or hacker rank and seeing people throw 1 line solved and theyre so complex in that one line that no one else unless they know the shortcuts will understand, completely destroying the whole point of teamwork

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

      I'm intrigued, how does this work? Oh wait, does it do 2 assignments at the same time, seperated by a comma? Holy 😨It's cool though.

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

      @@dscham1507 Yup. The comma on the right builds a 2-tuple out of the right and left values. The comma on the left pattern matches against sequences of length two and assigns the values it finds to the left and right attributes. It works because the entire expression to the right of the equal sign is evaluated before any of the assignments on the left occur.

  • @Nnm26
    @Nnm26 3 роки тому +53

    🎵"You suck at coding yeah you totally suck" 🎵

  • @jimbos22
    @jimbos22 3 роки тому +9

    "nice tree class, i always wanna make sure that i'm inverting the whole forest " this got me

  • @nicholast
    @nicholast 3 роки тому +3

    I have an interview next week and will definitely be using this strategy! Thanks Ben!

  • @BigBahss
    @BigBahss 3 роки тому +5

    This series is amazing, I love your subtle humor.

  • @juledz
    @juledz 3 роки тому +18

    That's how they made TENET just a bunch of transform classes

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

    Your explanation of swapping left and right was actually very welcome. I made the mistake of not using a temporary variable when I wrote my first swap function and I could not figure out why it wasn't working!!!

  • @ericlunadev
    @ericlunadev 3 роки тому +18

    8:55 You can do the variable swap in python without that tmp var. You just need to do: node.left, node.right = node.right, node.left

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

      You must be joking right ? Of course, he knows.

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

      but thats inferior to transform rotateY

  • @Noah-fx4cm
    @Noah-fx4cm 3 роки тому +7

    "they've never touched an underscore in their life" lmaoo, this speaks to me

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

    More of these videos from this Playlist please! Love them!

  • @user-xu7yf8gv2f
    @user-xu7yf8gv2f 3 роки тому +91

    Google Headquarters: " Don't give Ben a job , UA-cam will miss so many great videos "
    ❤️❤️🔥

    • @blink11101
      @blink11101 3 роки тому +6

      They already have, he's on their payroll thanks youtube. Ben is meta af lol

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

    As an Angular developer, I love you! Most amusing channel on UA-cam all-together!

  • @pratheeks
    @pratheeks 3 роки тому +3

    8:05 best explanation of screwing up swapping. Btw can we use (Node.left, Node.right) = (Node.right, Node.left)?
    Edit: It works, you don't even need to use the parentheses.

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

    I haven’t watched this channel in a couple years. Ben, you’re freakin hilarious now ahaha

  • @ismail.dalhatu
    @ismail.dalhatu 3 роки тому +1

    I’ve never being that happy for subscribing till today. 😂😂😂 I love the personality.

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

    You are getting really good at it, Man. Thanks for the video.

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

    This is the motivation I needed before applying and it's !important to watch twice before an interview.

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

      Watch it recursively with no base case, for sure

  • @JadeDevinCabatlao
    @JadeDevinCabatlao 3 роки тому +41

    "Binopus". For a moment, I heard something else.

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

    Ben, you have always been on my feed when I start watching more tech videos but I am legit subbing you after this. This is a masterpiece .. 😂😂 .. enjoyed the diss at microsoft and certain someone working there.. 🤣

  • @ivovanderknaap4616
    @ivovanderknaap4616 3 роки тому +5

    I'm doubting my entire codebase which was inspired by ben's full-stack tutorials now.

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

    For a second there I thought you're gonna use comic sans and my heart skipped a beat.

  • @fendoroid3788
    @fendoroid3788 3 роки тому +127

    Don't you hate when they reject you just because you can't invert a binary tree?

    • @Enroxxx
      @Enroxxx 3 роки тому +24

      inverting a binary tree it's super easy, barely an inconvenience.

    • @JOJO_THE_PROGRAMMER
      @JOJO_THE_PROGRAMMER 3 роки тому +2

      Data structure is fun

    • @seanlawton7681
      @seanlawton7681 3 роки тому +22

      It's a pointless demonstration of memory, like taking a test for school.

    • @Enroxxx
      @Enroxxx 3 роки тому +9

      @@seanlawton7681 do you think it is an algorithm that you need to memorize? LOL!!!

    • @seanlawton7681
      @seanlawton7681 3 роки тому +22

      @@Enroxxx We get it bro, you're very smart

  • @Fidelity_Investments
    @Fidelity_Investments 3 роки тому +3

    "The programming language I'd like to start with is CSS" ~Ben Awad, 2021.

  • @usmanmir5663
    @usmanmir5663 3 роки тому +22

    Last time I was this early I wrote 50 lines of code without a single error
    I was never this early

  • @luke7503
    @luke7503 3 роки тому +7

    It’s so well made that even with no coding knowledge I can tell this is cursed as fuck

  • @shreyanshmishra6613
    @shreyanshmishra6613 3 роки тому +7

    The css one got me...
    I laughed so hard!

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

    Bro this is killing me... So funny my lord a funny nerd. Subscribed, my man.

  • @user-se2tq1ls3v
    @user-se2tq1ls3v 3 роки тому +1

    I don't know if you all knew that but in python you can literally write-
    a, b = b, a
    this will switch those two and it's really nice and not very known

  • @frankeke8541
    @frankeke8541 3 роки тому +10

    7:53 tech with tim got roasteeeeed

  • @wewep6649
    @wewep6649 3 роки тому +9

    4:03 nice one!
    Now I can finally apply for a job at Google.

  • @twitchhighlights9802
    @twitchhighlights9802 3 роки тому +8

    I just started to code. Thanks for showing me how to get a job at Google. I think I'm going to pass it.

  • @nathanielwoodbury2692
    @nathanielwoodbury2692 3 роки тому +2

    Ben is literally my favorite tech channel on UA-cam

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

    This is the first video I watched in your channel. I pinched myself to check if I was dreaming.

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

    You can also go for node.left, node.right = node.right, node.left and that works well too

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

    the 5 spaces made me spill my drink

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

    Im not a python developer, but can't we swap variables in Python just like we can do with JS using array matching (destructuring) ? [a,b] = [b,a]

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

    Loved your coding style, loved your sense of humour.

  • @kaikalii
    @kaikalii 3 роки тому +3

    Counting out the spaces really got me

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

    I was going to sub regardless, but the !important completely sold me. Nice work!

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

    I'm currently trying to self learn, HTML and CSS were a breeze, JS on the other had is a little more tricky. Anyone have some tips or suggestions to help me out with JS retention/ learning?

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

    dude i was waiting for something like this :D, after that interview

  • @TwoTeaTee
    @TwoTeaTee 3 роки тому +5

    I'll be mad if he gets a call after this masterpiece!

  • @nilen
    @nilen 3 роки тому +3

    Thanks so much Ben

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

    this is the first of your vids that i'm watching. took me a while to figure out, that you're just trolling xD

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

    Solving a problem like this is really helpful. Expecting more..

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

    At 8:40
    node.left, node.right = node.right, node.left
    works too right?

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

    Ben, you are hilarious and instructive. Thanks for this 🙏

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

    the content just gets better and better

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

    Thanks for the tutorial, especially for the google docs dark mode extension

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

    Will the fix at 9:45 throw an error running under Deno?

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

    This made my whole morning XD

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

    I wanna learn how to code a website but I don’t know where to start. Could you give me some advice?

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

    Great stuff. And a nod (maybe) to the "You Suck At Photoshop" series.

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

    One of the hilarious videos I have watched in a while.

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

    First I thought it was an actual guide on inverting a binary tree... Got hired using this approach, thanks!

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

    My CSS binary tree returned a 500 error, is that good?

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

    Your content is amazing I had to subscribe.

  • @emilfilipov169
    @emilfilipov169 3 роки тому +7

    Most of them are C++ chads and have never touched an underscore in their lives xDD I'm dying!

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

    Ben, what do you think of prisma 2 vs typeORM? greetings from Chile.

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

    The "ad" actually popped up at the end of the video!

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

    I never thought that Comfortaa is actually a good font.

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

    Damn I don't normally like youtube videos but this is just too good lol

  • @migueldomingos4570
    @migueldomingos4570 3 роки тому +3

    This is way too comic😂. The few videos I still watch at 1x

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

    Important facts, made even better with the cedar waxwing cameo at the end. Those birds get drunk on berries, that's probably why they want to get inverted.

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

    What's practical usecases of inverting like filesystem or indexing

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

    Alt+F4 to open dev tools is now my favourite shortcut

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

    0:40 I lost it here 🤣🤣 Jeez I'm amazed you made it though with a straight face.
    Edit: Okay I love your humour 🤣🤣🤣🤣🤣 This one was incredible!

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

    I came here for a serious video and I was not disappointed. loved it!

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

    I really enjoyed your videos, the jokes are really put me in good mode. Thanks Ben 🖐

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

    This should be in youtube rewind 2021 or get an Oscar or even a Turing award

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

    Love it, recommended to my A Level CS students. Left arms frequently get chopped off. I'm concerned that some won't get the humour, but hey, that's life in the big city.

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

    This is so funny! Brilliant Job!

  • @ahmedal-qarqaz3510
    @ahmedal-qarqaz3510 3 роки тому

    This video has better CS comedy than the entirety of silicon valley

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

    this video taught me that i know nothing about coding, i need to re-learn everything that sucks ._.

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

    This is really, REALLY good.

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

    Love how the image is commented!