babybear4812
babybear4812
  • 82
  • 226 516
How to Solve ANY Dynamic Programming Problem
A comprehensive and exhaustive guide to answering ANY DP problem that may come your way. Let me know if you have any questions :)
ARTICLE: medium.com/@mitrovic.aleksandar/the-ultimate-guide-to-dynamic-programming-65865ef7ec5b
UNIQUE PATHS VIDEO: th-cam.com/video/vzzJpyDyE3g/w-d-xo.html
leetcode.com/problems/unique-paths/
---------------------------------------------------------------------------------------------------------------------------------------------------------------
Let's connect on LinkedIn!
www.linkedin.com/in/aleksmitrovic/
Follow me on Medium!
medium.com/@mitrovic.aleksandar
Questions or suggestions for new videos? Email me!
babybear4812@gmail.com
มุมมอง: 7 978

วีดีโอ

MAXIMUM PERFORMANCE OF A TEAM (Leetcode) - Code & Whiteboard
มุมมอง 3K3 ปีที่แล้ว
An O(NlogN) time and O(N) space solution to Leetcode 1383 - Maximum Performance of a Team, as being asked by DoorDash! Let me know down below if you have any questions :) leetcode.com/problems/maximum-performance-of-a-team/ Let's connect on LinkedIn! www.linkedin.com/in/aleksmitrovic/ Follow me on Medium! medium.com/@mitrovic.aleksandar Questions or suggestions for new videos? Email me! babybea...
RANDOM PICK WITH BLACKLIST (Leetcode) - Code & Whiteboard
มุมมอง 2K3 ปีที่แล้ว
Leetcode 710 is a really tricky problem being asked by Two Sigma that requires a rather unique algorithm to solve efficiently! Let me know if you have any questions below! :) leetcode.com/problems/random-pick-with-blacklist/ Let's connect on LinkedIn! www.linkedin.com/in/aleksmitrovic/ Follow me on Medium! medium.com/@mitrovic.aleksandar Questions or suggestions for new videos? Email me! babybe...
COUNT UNHAPPY FRIENDS (Leetcode) - Code & Whiteboard
มุมมอง 3.7K3 ปีที่แล้ว
A tricky Bloomberg favourite! Thankfully, the solution itself is quite succinct :) Time Complexity: O(n^2). For each of the n people, we will walk through (up to) n-1 entries in their preferences. Therefore, n * (n-1) approaches O(n^2). Space Complexity: O(n^2). We will have n entries in the dictionary we create, and each one of those can have (up to) n-1 entries in the set. Therefore, n * (n-1...
FIND MEDIAN FROM DATA STREAM (Leetcode) - Code & Whiteboard
มุมมอง 1.6K3 ปีที่แล้ว
A great problem (with an even better solution) that's being asked by all of the FAANG companies! Let me know if you have any questions down below :) Let's connect on LinkedIn! www.linkedin.com/in/aleksmitrovic/ Follow me on Medium! medium.com/@mitrovic.aleksandar Questions or suggestions for new videos? Email me! babybear4812@gmail.com
SHOPPER'S DELIGHT - IBM INTERVIEW QUESTION - Code & Whiteboard
มุมมอง 4.7K3 ปีที่แล้ว
TYPO @ 19:38 - should be greater than, not less than!! This is my absolute favourite problem and solution to any Data Structure & Algorithm problem I've come across to date. The question is being asked by IBM in their Online Assessment (at least) for backend developers. Let me know if you'd like to see more of these kinds of questions! :) Let's connect on LinkedIn! www.linkedin.com/in/aleksmitr...
BINARY TREE RIGHT SIDE VIEW (Leetcode) - Code & Whiteboard
มุมมอง 4483 ปีที่แล้ว
A cheeky O(N) solution to Facebook's popular Binary Tree Right Side View problem Leetcode #199. Let me know if you have any questions down below! :) leetcode.com/problems/binary-tree-right-side-view/ Let's connect on LinkedIn! www.linkedin.com/in/aleksmitrovic/ Follow me on Medium! medium.com/@mitrovic.aleksandar Questions or suggestions for new videos? Email me! babybear4812@gmail.com
LEFTMOST COLUMN WITH AT LEAST A ONE (Leetcode) - Code & Whiteboard
มุมมอง 5533 ปีที่แล้ว
One of Facebook's most popular problems in the past 6 months! Let me know if you have any questions down below :) leetcode.com/problems/leftmost-column-with-at-least-a-one/ Let's connect on LinkedIn! www.linkedin.com/in/aleksmitrovic/ Follow me on Medium! medium.com/@mitrovic.aleksandar Questions or suggestions for new videos? Email me! babybear4812@gmail.com
CONVERT BINARY SEARCH TREE TO SORTED DOUBLY LINKED LIST (Leetcode) - Code & Whiteboard
มุมมอง 6K3 ปีที่แล้ว
One of Facebook's most recently asked questions of the past 6 months! Let me know down below if you have any questions :) leetcode.com/problems/convert-binary-search-tree-to-sorted-doubly-linked-list/ Let's connect on LinkedIn! www.linkedin.com/in/aleksmitrovic/ Follow me on Medium! medium.com/@mitrovic.aleksandar Questions or suggestions for new videos? Email me! babybear4812@gmail.com
REGULAR EXPRESSION MATCHING (Leetcode) - Code & Whiteboard
มุมมอง 4.2K3 ปีที่แล้ว
SUPER TOUGH PROBLEM that's currently being asked by Amazon and Facebook! This one's a real headache but I hope this video helps clarify things :) Here's a FREE, IN-DEPTH article I wrote about solving Dynamic Programming problems. It talks about how to approach and evolve your DP solutions over the course of an interview, from soup to nuts! I hope you find it useful: medium.com/@mitrovic.aleksan...
NUMBER OF PROVINCES (Leetcode) - Code & Whiteboard
มุมมอง 21K3 ปีที่แล้ว
CORRECTION: The time complexity is actually O(N). See the discussion in the pinned comments for an explanation :) Leetcode 547 has been super popular with Amazon and Goldman Sachs recently! Have a look and let me know if you have any questions or comments :) leetcode.com/problems/number-of-provinces/ Let's connect on LinkedIn! www.linkedin.com/in/aleksmitrovic/ Follow me on Medium! medium.com/@...
REORGANIZE STRING (Leetcode) - Code & Whiteboard
มุมมอง 2K3 ปีที่แล้ว
SEE PINNED COMMENT: I made a mistake in my understanding of how the `charCountsIdx` integer works around the ~28 min mark. @Martial Studiôs was kind enough to point out the mistake and explain the correctly how the code actually worked in this small segment. Thank you! Also, I have no damn idea why my beard came out looking so uneven here. I promise I know how to trim. This problem has been pop...
LFU CACHE (Leetcode) - Code & Whiteboard
มุมมอง 6K4 ปีที่แล้ว
This one's tough! We break down the constant time solution on implementing a Least Frequently Used Cache. Let me know down below if you have any questions or comments :) leetcode.com/problems/lfu-cache/ Let's connect on LinkedIn! www.linkedin.com/in/aleksmitrovic/ Follow me on Medium! medium.com/@mitrovic.aleksandar Questions or suggestions for new videos? Email me! babybear4812@gmail.com
UNIQUE PATHS (Leetcode) - Code & Whiteboard
มุมมอง 8794 ปีที่แล้ว
An O(n*m) solution to Unique Paths, along with a bonus O(1) solution at the end of the video :) Let me know what you guys think, and if you have any suggestions about what to answer next! leetcode.com/problems/unique-paths/ Let's connect on LinkedIn! www.linkedin.com/in/aleksmitrovic/ Follow me on Medium! medium.com/@mitrovic.aleksandar Questions or suggestions for new videos? Email me! babybea...
NUMBER OF SHIPS IN A RECTANGLE (Leetcode) - Code & Whiteboard
มุมมอง 5K4 ปีที่แล้ว
Check the pinned comment to have a look at a more detailed explanation of why this solution satisfies the limit of at most 400 API calls; I briefly brushed it off in the video as I wasn't entirely sure, but one of our viewers seems to have gotten it! :) A logarithmic solution to Leetcode 1274 - Number of Ships in a Rectangle. It's a tricky problem! Let me know if you have any questions about it...
GROUP ANAGRAMS (Leetcode) - Code & Whiteboard
มุมมอง 3064 ปีที่แล้ว
GROUP ANAGRAMS (Leetcode) - Code & Whiteboard
LONGEST INCREASING PATH IN A MATRIX (Leetcode) - Code & Whiteboard
มุมมอง 1K4 ปีที่แล้ว
LONGEST INCREASING PATH IN A MATRIX (Leetcode) - Code & Whiteboard
DESIGN SEARCH AUTOCOMPLETE SYSTEM (Leetcode) - Code & Whiteboard
มุมมอง 6K4 ปีที่แล้ว
DESIGN SEARCH AUTOCOMPLETE SYSTEM (Leetcode) - Code & Whiteboard
RESTORE IP ADDRESSES (Leetcode) - Code & Whiteboard
มุมมอง 3.1K4 ปีที่แล้ว
RESTORE IP ADDRESSES (Leetcode) - Code & Whiteboard
LARGEST BST SUBTREE (Leetcode) - Code & Whiteboard
มุมมอง 2.2K4 ปีที่แล้ว
LARGEST BST SUBTREE (Leetcode) - Code & Whiteboard
LOWEST COMMON ANCESTOR OF DEEPEST LEAVES (Leetcode) - Code & Whiteboard
มุมมอง 8494 ปีที่แล้ว
LOWEST COMMON ANCESTOR OF DEEPEST LEAVES (Leetcode) - Code & Whiteboard
POW(X, N) (Leetcode) - Code & Whiteboard
มุมมอง 8854 ปีที่แล้ว
POW(X, N) (Leetcode) - Code & Whiteboard
MAXIMUM WIDTH OF BINARY TREE (Leetcode) - Code & Whiteboard
มุมมอง 1.7K4 ปีที่แล้ว
MAXIMUM WIDTH OF BINARY TREE (Leetcode) - Code & Whiteboard
FLATTEN A MULTILEVEL DOUBLY LINKED LIST (Leetcode) - Code & Whiteboard
มุมมอง 3.7K4 ปีที่แล้ว
FLATTEN A MULTILEVEL DOUBLY LINKED LIST (Leetcode) - Code & Whiteboard
TWO CITY SCHEDULING (Leetcode) - Code & Whiteboard
มุมมอง 1.1K4 ปีที่แล้ว
TWO CITY SCHEDULING (Leetcode) - Code & Whiteboard
BEST TIME TO BUY AND SELL STOCK IV (Leetcode) - Code & Whiteboard
มุมมอง 8454 ปีที่แล้ว
BEST TIME TO BUY AND SELL STOCK IV (Leetcode) - Code & Whiteboard
WORD SQUARES (Leetcode) - Code & Whiteboard
มุมมอง 3K4 ปีที่แล้ว
WORD SQUARES (Leetcode) - Code & Whiteboard
NON-DECREASING ARRAY (Leetcode) - Code & Whiteboard
มุมมอง 1.3K4 ปีที่แล้ว
NON-DECREASING ARRAY (Leetcode) - Code & Whiteboard
COUNT COMPLETE TREE NODES (Leetcode) - Code & Whiteboard
มุมมอง 1.2K4 ปีที่แล้ว
COUNT COMPLETE TREE NODES (Leetcode) - Code & Whiteboard
SUM OF MUTATED ARRAY CLOSEST TO TARGET (Leetcode) - Code & Whiteboard
มุมมอง 1.8K4 ปีที่แล้ว
SUM OF MUTATED ARRAY CLOSEST TO TARGET (Leetcode) - Code & Whiteboard

ความคิดเห็น

  • @ankushreddy9789
    @ankushreddy9789 6 วันที่ผ่านมา

    this is by far the best explanation for this question

    • @babybear-hq9yd
      @babybear-hq9yd 19 ชั่วโมงที่ผ่านมา

      glad to hear thanks man

  • @yomamasofat413
    @yomamasofat413 13 วันที่ผ่านมา

    greaaaaaaaaaaaaat video I finally get it

  • @NiranjanMadhavanD
    @NiranjanMadhavanD 14 วันที่ผ่านมา

    I absolutely loveddd this explanation! Seriously! this is sooo good! I hope you make more such videos!

    • @babybear-hq9yd
      @babybear-hq9yd 19 ชั่วโมงที่ผ่านมา

      thx man! Haven't touched this stuff in years so I think we can label this channel as archived

  • @hazelpham2404
    @hazelpham2404 28 วันที่ผ่านมา

    very clear explanation!!! thanks

  • @techpiano7010
    @techpiano7010 หลายเดือนก่อน

    Thank you sir.I needed this video at this time!😄

    • @babybear-hq9yd
      @babybear-hq9yd หลายเดือนก่อน

      glad it helped mate

  • @anoops7974
    @anoops7974 หลายเดือนก่อน

    Great explanation. Thank youuu !!

  • @MattieRamos
    @MattieRamos 2 หลายเดือนก่อน

    Dude, thank you for this. Embarrassed to say that I've been coming back to this problem for a week while working on Binary Search. LeetCode has this listed as an "easy" problem. I feel as if you just do it recursively then yes, it's easy to solve. But using Binary Search to optimize it turned into a lot of googling and youtubing that made no sense until I came across this video. Thanks again!

  • @sumitvaise5452
    @sumitvaise5452 3 หลายเดือนก่อน

    explanation is just amazing, thank you!

  • @bag_of_pixels
    @bag_of_pixels 4 หลายเดือนก่อน

    For those, who like me still didn't understand solution after video, here code in python: ```python from typing import List import logging logging.basicConfig(level=logging.DEBUG) logger = logging.getLogger(__name__) def findCircleNum(isConnected: List[List[int]]) -> int: cnt, visited, l = 0, set(), len(isConnected) def dfs(start: int): visited.add(start) for end in range(l): if isConnected[start][end] and end not in visited: dfs(end) for start in range(l): if start not in visited: cnt += 1 dfs(start) return cnt if __name__ == "__main__": test_cases = [ [[1, 1, 0], [1, 1, 0], [0, 0, 1]], [[1, 0, 0], [0, 1, 0], [0, 0, 1]], [[1, 0, 0, 1], [0, 1, 1, 0], [0, 1, 1, 1], [1, 0, 1, 1]], ] expected = [2, 3, 1] for index, item in enumerate(test_cases): res = findCircleNum(item) logger.debug(f"res == {res}, expected == {expected[index]}") ``` Simply speaking, dfs marks as `visited` all the linked to current item nodes, therefore in the main loop `cnt += 1` called only for remaining nodes

  • @tindo0038
    @tindo0038 4 หลายเดือนก่อน

    I understand the implementation part, but I am not sure why we are interested in the earliest end time :(. greedy is tough, man.

    • @babybear-hq9yd
      @babybear-hq9yd 4 หลายเดือนก่อน

      I haven't looked at this problem or any Leetcode in almost 3 years, but from what I recall, that's roughly covered around 6:30. Conceptually, if I need a meeting room & all current rooms are being used/are booked, I am going to look for the one that ends soonest because that is the first one that I will occupy if it is available at my time.

    • @tindo0038
      @tindo0038 4 หลายเดือนก่อน

      @@babybear-hq9yd thank you!

  • @ani_jonah
    @ani_jonah 4 หลายเดือนก่อน

    what pen and setup do you use to draw diagrams?

    • @babybear-hq9yd
      @babybear-hq9yd 4 หลายเดือนก่อน

      I used sketchpad for the online whiteboard, and used a HUION 420 Drawing Tablet for the pen/tablet setup.

    • @ani_jonah
      @ani_jonah 4 หลายเดือนก่อน

      @@babybear-hq9yd thanks!

  • @Vlad1998996
    @Vlad1998996 4 หลายเดือนก่อน

    you are great <3

  • @RolopIsHere
    @RolopIsHere 4 หลายเดือนก่อน

    it took me 45 minutes to use the trie version of this, and I found yours, I am using this version from now on. Thanks!

    • @babybear-hq9yd
      @babybear-hq9yd 4 หลายเดือนก่อน

      love to hear it, glad it helped man!

  • @htchannel123
    @htchannel123 5 หลายเดือนก่อน

    Thank you so much for giving a great explanation.

  • @asimzuhaib2451
    @asimzuhaib2451 6 หลายเดือนก่อน

    bc angrezo thoda dheere bol liya kro banda smaghne aaya hai

  • @ANUSHAKRISHNA-m1k
    @ANUSHAKRISHNA-m1k 7 หลายเดือนก่อน

    This is the simplest version I've come across, can't thank you enough

    • @babybear-hq9yd
      @babybear-hq9yd 7 หลายเดือนก่อน

      glad it helped :)

  • @inderbindra87
    @inderbindra87 7 หลายเดือนก่อน

    @babybear4812 - The time complexity of the code will O(N^2) as in the worst case when none of the cities is connected, in that case, the DFS method will called N times, and the outer loop will also be executed n times making it O(N^2).

  • @AlexBlack-xz8hp
    @AlexBlack-xz8hp 8 หลายเดือนก่อน

    Your video took this from being pretty incomprehensible to me to being super trivial in 20 minuts. Thank you sooooo much for your very clear explanation. It was incredibly helpful.

    • @babybear-hq9yd
      @babybear-hq9yd 8 หลายเดือนก่อน

      glad it helped bro!

  • @saitmesutcanilhaner8850
    @saitmesutcanilhaner8850 8 หลายเดือนก่อน

    Best explanation I have seen. Thank you very much! The solution seems simple but it is not easy to come up with the solution on the spot especially given the limited amount of time in the interviews. I don't think I would be able to fully solve this myself in 20 minutes.

    • @babybear-hq9yd
      @babybear-hq9yd 8 หลายเดือนก่อน

      simple != easy :)

  • @DenysGarbuz
    @DenysGarbuz 9 หลายเดือนก่อน

    trash solution with comprehensive amount of code even using queue, when problem states that you should use constant space. The coolest approach I have seen, is "needle" approach, when we use each lvl of tree as linked list nodes. it uses O(1)

  • @sayeedchowdhury11
    @sayeedchowdhury11 9 หลายเดือนก่อน

    Excellent video, subbed, keep it up

  • @shadowhawk5511
    @shadowhawk5511 9 หลายเดือนก่อน

    Thank you for mentioning about aliasing on curPath array when we directly add to result array!

  • @nithinsastrytellapuri291
    @nithinsastrytellapuri291 10 หลายเดือนก่อน

    Great explanation !

  • @JarvisBirmingham-b8q
    @JarvisBirmingham-b8q 10 หลายเดือนก่อน

    Request for toonblast leetcode

  • @iiilllilllliiiiiillllliiii5613
    @iiilllilllliiiiiillllliiii5613 11 หลายเดือนก่อน

    Amazing!

  • @shivangrathore
    @shivangrathore ปีที่แล้ว

    This problem was so confusing for me to understand, thanks for explaining

    • @babybear-hq9yd
      @babybear-hq9yd 11 หลายเดือนก่อน

      my pleasure bud!!

  • @J1MKAKA1N
    @J1MKAKA1N ปีที่แล้ว

    Much thanks, quite clearly explained!

    • @babybear-hq9yd
      @babybear-hq9yd 11 หลายเดือนก่อน

      no worries dude!

  • @m4hi2
    @m4hi2 ปีที่แล้ว

    Hey, great explaination and video. But I think leetcode has introduced some new test cases and this approach doesn't work anymore. I've followed this and coded up the Go version but it got WA. Directly copied the python version still got WA. 😞

    • @babybear-hq9yd
      @babybear-hq9yd 11 หลายเดือนก่อน

      ah bummer sorry to hear. haven't touched this stuff in a few years so can't help much

    • @m4hi2
      @m4hi2 11 หลายเดือนก่อน

      @@babybear-hq9yd no worries, solved it. just wanted to let you know. thanks for the content.

  • @bhushankhope8949
    @bhushankhope8949 ปีที่แล้ว

    what is the time and space complexity of this code?

    • @babybear-hq9yd
      @babybear-hq9yd 11 หลายเดือนก่อน

      probably O(n*m) if i remember correctly

  • @NextGenAdvancedNerd
    @NextGenAdvancedNerd ปีที่แล้ว

    yes,bear is right about nonlocal declaration ,we use global var inside function incase we need to update a variable declare/used outside of a function and can be used throughout code .similarly we use non local var inside nested function incase we need to update a variable declared in the outer function.local is when we declare and use variables inside any function.

  • @ManishaSharma-o5t
    @ManishaSharma-o5t ปีที่แล้ว

    best best best explanation :)

  • @el_m_ghoul
    @el_m_ghoul ปีที่แล้ว

    Nice one, man. Thanks.

  • @arunimachakraborty1175
    @arunimachakraborty1175 ปีที่แล้ว

    Its that simple? 😲😲😲 OMG thanks a lot for this

  • @eugeniocastro5118
    @eugeniocastro5118 ปีที่แล้ว

    buena viejo, explicaste chido

  • @northridgefield
    @northridgefield ปีที่แล้ว

    cool explanation, thanks :)

  • @malikjavaid3029
    @malikjavaid3029 ปีที่แล้ว

    goated video

  • @geob7o
    @geob7o ปีที่แล้ว

    Yesss, the fact that they call top right before bottom left is low key really confusing 😅

  • @rohanchess8332
    @rohanchess8332 ปีที่แล้ว

    I think there is confusion in the complexity, lets say the graph is only directly connected pairwise (like 1-2, 3-4, 5-6 ... etc) in that case the dfs function will be called N/2 time and therefore time complexity is O(N^2) only. We are supposed to track how many times dfs function will be called, not how many times a node gets visited.

  • @NitirajSinghRathore
    @NitirajSinghRathore ปีที่แล้ว

    Just remove the ANY word from the title. Because this is all the theory etc and even the intuition is discussed everywhere, books, videos etc. But all that still does not help when trying to solve a difficult problem. So I was expecting that you will also introduce the intuition both for recursion and DP with more complex problems so that practice and thought process will help solve ANY problem. But you just discussed one problem and probably the most easiest one and call the video title as ANY. I can guarantee that just by watching this video even you will not be able to the next difficult problem where DP will "improve" the recursion. Ask yourself.

  • @vortexgamingtv0
    @vortexgamingtv0 ปีที่แล้ว

    what would be the time complexity with and without using memo ??

  • @KiyotakaAyanokoji1
    @KiyotakaAyanokoji1 ปีที่แล้ว

    it really gave clarity through that dry run!! , i think i mis-read the question though , . . . . .what i thought was -> , it was necessary that we have exgatly k employees selected ? our(your) code can give (maximum )answer even when we dont consider k people , but less than k people , , here is a test case . . . . eff = [100 , 1 , 1] , speed = [100 , 1 , 1 ] k = 3 , so we need 3 people but taking only the first guy gives us the answer as 100*100 , while taking all three of them reduces our answer to 1*(100+1+1)=102 , ,, , this is could be a variant to the original question , small change to our code like start taking maximum only when the size of heap has reached k should just do the thing!! Happy learning !

  • @vikashmaurya2679
    @vikashmaurya2679 ปีที่แล้ว

    Subscription added

  • @MuhammadNiaazWahab
    @MuhammadNiaazWahab ปีที่แล้ว

    How come it’s enough for you to DFS from the curr as START only? How come we don’t have to also consider other STARTS for this (using curr as END) So if for example were iterating on START =2. So yes we check all the [2][0…5]. But how about checking the [0…5][2] ones too?

  • @muditkhanna8164
    @muditkhanna8164 ปีที่แล้ว

    this is the best explanation out there for word break 2

  • @AiminglowNAccpble
    @AiminglowNAccpble ปีที่แล้ว

    12:16

  • @rydmerlin
    @rydmerlin ปีที่แล้ว

    Can you define dfs as a nested function and keep graph outside it? Then you don’t need it as a parameter do you? Why in the official solution do they choose to unmark currNode from visited at the end of dfs?

    • @babybear-hq9yd
      @babybear-hq9yd ปีที่แล้ว

      You probably could nest it, i don't see why not. And I'm not sure about the official solution I haven't looked at this in years. An initial guess may be because if you don't unmark it as visited, their solution may not know where to continue searching from, but tough to say without having looked at it

  • @robertuptc
    @robertuptc ปีที่แล้ว

    Very nice explanation, easy to follow. Drawings definetely help a lot. Thanks man

  • @rydmerlin
    @rydmerlin ปีที่แล้ว

    Did you ever interview at FAANG? And why are you so happy when doing Leetcode ? :-)

    • @babybear-hq9yd
      @babybear-hq9yd ปีที่แล้ว

      1. i don't work in the SWE space 2. i was young and naive :')

  • @fgtdjkg
    @fgtdjkg ปีที่แล้ว

    wawaweewa, it's a very nice!

  • @kayehong3615
    @kayehong3615 ปีที่แล้ว

    It's great. Your idea is more understandable and helpful than leetcode card for me. I'm lucky today to meet your video. Thank you so much.