Greg Hogg
Greg Hogg
  • Видео 861
  • Просмотров 24 408 320
Find Closest Number to Zero - Leetcode 2239 - Arrays & Strings (Python)
The Python code for this problem can be found at my GitHub repo here: github.com/gahogg/Leetcode-Solutions/blob/main/Fibonacci%20Number%20-%20Leetcode%20509.py
Please check my playlists for free DSA problem solutions:
ruclips.net/p/PLKYEe2WisBTFlP0RlwfwPrdkvHrcTBUg-
ruclips.net/p/PLKYEe2WisBTEK8_GVXySX9aDWBHk5fGwQ
ruclips.net/p/PLKYEe2WisBTFZH-p9jgAOwtHy9_LGI28W
ruclips.net/p/PLKYEe2WisBTH7I9sCPjSZCs-iBAH4ybmS
ruclips.net/p/PLKYEe2WisBTH601scI_A008gm34oARlIp&si=DnCpq_RiFkObYn7p
ruclips.net/p/PLKYEe2WisBTF21RGRtZfGGolpHmca_d3N
ruclips.net/p/PLKYEe2WisBTH48RzVCL_LQrGW-ahPY44S
ruclips.net/p/PLKYEe2WisBTHcWHAGWvKJuVMu5ElMA18M
ruclips.net/p/PLKYEe2WisBTEY7eJBW7W-jbxlXCGb928P
ruclips.net/p/PLKYEe2WisBTHCm...
Просмотров: 349

Видео

Static Arrays, Dynamic Arrays, and Strings - Big O Complexity - DSA Course in Python Lecture 2
Просмотров 1,3 тыс.7 часов назад
The previous lesson in this DSA course can be found at this link: ruclips.net/video/aWKEBEg55ps/видео.html The Python Colab notebook can be found at this link: colab.research.google.com/drive/1U9tv4lgJ6HV-e_h4MdBlgqlbqw8IogSJ?usp=sharing Please check my playlists for free DSA problem solutions: ruclips.net/p/PLKYEe2WisBTFlP0RlwfwPrdkvHrcTBUg- ruclips.net/p/PLKYEe2WisBTEK8_GVXySX9aDWBHk5fGwQ ruc...
Time & Space Complexity - Big O Notation - DSA Course in Python Lecture 1
Просмотров 2 тыс.14 часов назад
The next lesson in my DSA course can be found here: ruclips.net/video/TQMvBTKn2p0/видео.html Please check my playlists for free DSA problem solutions: ruclips.net/p/PLKYEe2WisBTFlP0RlwfwPrdkvHrcTBUg- ruclips.net/p/PLKYEe2WisBTEK8_GVXySX9aDWBHk5fGwQ ruclips.net/p/PLKYEe2WisBTFZH-p9jgAOwtHy9_LGI28W ruclips.net/p/PLKYEe2WisBTH7I9sCPjSZCs-iBAH4ybmS ruclips.net/p/PLKYEe2WisBTH601scI_A008gm34oARlIp&s...
Implement Trie (Prefix Tree) - Leetcode 208 - Trees (Python)
Просмотров 1,5 тыс.16 часов назад
The Python code for this problem can be found at my GitHub repo here: github.com/gahogg/Leetcode-Solutions/blob/main/Fibonacci Number - Leetcode 509.py Please check my playlists for free DSA content: Fundamentals: ruclips.net/p/PLKYEe2WisBTGq9T0wPulXz1otUsVeOGey Arrays & Strings: ruclips.net/p/PLKYEe2WisBTFlP0RlwfwPrdkvHrcTBUg- Hashmaps: ruclips.net/p/PLKYEe2WisBTFvzq98lMIhWfXH3KMTXZv0 2 Pointe...
Minimum Absolute Difference in BST - Leetcode 530 - Trees (Python)
Просмотров 79319 часов назад
The Python code for this problem can be found at my GitHub repo here: github.com/gahogg/Leetcode-Solutions/blob/main/Fibonacci Number - Leetcode 509.py Please check my playlists for free DSA problem solutions: ruclips.net/p/PLKYEe2WisBTFlP0RlwfwPrdkvHrcTBUg- ruclips.net/p/PLKYEe2WisBTEK8_GVXySX9aDWBHk5fGwQ ruclips.net/p/PLKYEe2WisBTFZH-p9jgAOwtHy9_LGI28W ruclips.net/p/PLKYEe2WisBTH7I9sCPjSZCs-i...
Summary Ranges - Leetcode 228 - Arrays & Strings (Python)
Просмотров 76819 часов назад
The Python code for this problem can be found at my GitHub repo here: github.com/gahogg/Leetcode-Solutions/blob/main/Fibonacci Number - Leetcode 509.py Please check my playlists for free DSA problem solutions: ruclips.net/p/PLKYEe2WisBTFlP0RlwfwPrdkvHrcTBUg- ruclips.net/p/PLKYEe2WisBTEK8_GVXySX9aDWBHk5fGwQ ruclips.net/p/PLKYEe2WisBTFZH-p9jgAOwtHy9_LGI28W ruclips.net/p/PLKYEe2WisBTH7I9sCPjSZCs-i...
Is Subsequence - Leetcode 392 - Arrays & Strings (Python)
Просмотров 74219 часов назад
The Python code for this problem can be found at my GitHub repo here: github.com/gahogg/Leetcode-Solutions/blob/main/Fibonacci Number - Leetcode 509.py Please check my playlists for free DSA problem solutions: ruclips.net/p/PLKYEe2WisBTFlP0RlwfwPrdkvHrcTBUg- ruclips.net/p/PLKYEe2WisBTEK8_GVXySX9aDWBHk5fGwQ ruclips.net/p/PLKYEe2WisBTFZH-p9jgAOwtHy9_LGI28W ruclips.net/p/PLKYEe2WisBTH7I9sCPjSZCs-i...
Roman to Integer - Leetcode 13 - Arrays & Strings (Python)
Просмотров 1,6 тыс.19 часов назад
The Python code for this problem can be found at my GitHub repo here: github.com/gahogg/Leetcode-Solutions/blob/main/Fibonacci Number - Leetcode 509.py Please check my playlists for free DSA problem solutions: ruclips.net/p/PLKYEe2WisBTFlP0RlwfwPrdkvHrcTBUg- ruclips.net/p/PLKYEe2WisBTEK8_GVXySX9aDWBHk5fGwQ ruclips.net/p/PLKYEe2WisBTFZH-p9jgAOwtHy9_LGI28W ruclips.net/p/PLKYEe2WisBTH7I9sCPjSZCs-i...
Kth Smallest Element in a BST - Leetcode 230 - Trees (Python)
Просмотров 1,1 тыс.21 час назад
Kth Smallest Element in a BST - Leetcode 230 - Trees (Python)
Majority Element - Leetcode 169 - Hashmaps & Sets (Python)
Просмотров 1,1 тыс.21 час назад
Majority Element - Leetcode 169 - Hashmaps & Sets (Python)
Merge K Sorted Linked Lists - Leetcode 23 - Heaps (Python)
Просмотров 1,1 тыс.День назад
Merge K Sorted Linked Lists - Leetcode 23 - Heaps (Python)
Longest Common Prefix - Leetcode 14 - Arrays & Strings (Python)
Просмотров 1,5 тыс.День назад
Longest Common Prefix - Leetcode 14 - Arrays & Strings (Python)
Average of Levels in Binary Tree - Leetcode 637 - Trees (Python)
Просмотров 490День назад
Average of Levels in Binary Tree - Leetcode 637 - Trees (Python)
Path Sum - Leetcode 112 - Trees (Python)
Просмотров 922День назад
Path Sum - Leetcode 112 - Trees (Python)
Minimum Size Subarray Sum - Leetcode 209 - Sliding Window (Python)
Просмотров 1 тыс.День назад
Minimum Size Subarray Sum - Leetcode 209 - Sliding Window (Python)
Symmetric Tree - Leetcode 101 - Trees (Python)
Просмотров 552День назад
Symmetric Tree - Leetcode 101 - Trees (Python)
Best Time to Buy and Sell Stock - Leetcode 121 - Arrays & Strings (Python)
Просмотров 1,4 тыс.День назад
Best Time to Buy and Sell Stock - Leetcode 121 - Arrays & Strings (Python)
Spiral Matrix - Leetcode 54 - Arrays & Strings (Python)
Просмотров 1,5 тыс.14 дней назад
Spiral Matrix - Leetcode 54 - Arrays & Strings (Python)
Rotate Image - Leetcode 48 - Arrays & Strings (Python)
Просмотров 2,8 тыс.14 дней назад
Rotate Image - Leetcode 48 - Arrays & Strings (Python)
Merge Intervals - Leetcode 56 - Arrays & Strings (Python)
Просмотров 1,2 тыс.14 дней назад
Merge Intervals - Leetcode 56 - Arrays & Strings (Python)
Kth Largest Element in an Array - Leetcode 215 - Heaps (Python)
Просмотров 2,5 тыс.14 дней назад
Kth Largest Element in an Array - Leetcode 215 - Heaps (Python)
Last Stone Weight - Leetcode 1046 - Heaps (Python)
Просмотров 1,2 тыс.14 дней назад
Last Stone Weight - Leetcode 1046 - Heaps (Python)
Longest Common Subsequence - Leetcode 1143 - Dynamic Programming (Python)
Просмотров 1,1 тыс.14 дней назад
Longest Common Subsequence - Leetcode 1143 - Dynamic Programming (Python)
Longest Increasing Subsequence - Leetcode 300 - Dynamic Programming (Python)
Просмотров 1,3 тыс.21 день назад
Longest Increasing Subsequence - Leetcode 300 - Dynamic Programming (Python)
Jump Game - Leetcode 55 - Dynamic Programming (Python)
Просмотров 90421 день назад
Jump Game - Leetcode 55 - Dynamic Programming (Python)
Maximum Subarray (Kadane's Algorithm) - Leetcode 53 - Dynamic Programming (Python)
Просмотров 2 тыс.21 день назад
Maximum Subarray (Kadane's Algorithm) - Leetcode 53 - Dynamic Programming (Python)
Coin Change - Leetcode 322 - Dynamic Programming (Python)
Просмотров 2,2 тыс.21 день назад
Coin Change - Leetcode 322 - Dynamic Programming (Python)
Unique Paths - Leetcode 62 - Dynamic Programming (Python)
Просмотров 1,1 тыс.21 день назад
Unique Paths - Leetcode 62 - Dynamic Programming (Python)
Strong Noob Programmer vs O(n) Remote Engineer on Best Time to Buy and Sell Stock, Leetcode 121
Просмотров 10 тыс.21 день назад
Strong Noob Programmer vs O(n) Remote Engineer on Best Time to Buy and Sell Stock, Leetcode 121
Reversed O(n^2) Developer vs Skilled Heap O(n log n) Engineer on Last Stone Weight, Leetcode 1046
Просмотров 7 тыс.21 день назад
Reversed O(n^2) Developer vs Skilled Heap O(n log n) Engineer on Last Stone Weight, Leetcode 1046

Комментарии

  • @sabeetspongiinchowdhury3965
    @sabeetspongiinchowdhury3965 35 минут назад

    Sup grg

  • @abba5102
    @abba5102 49 минут назад

    You are doing really well. Thank you.

  • @tomislam
    @tomislam 59 минут назад

    One pass? On a phone, didn't get to check all edge cases. def closest(arr): if len(arr) == 1: return arr[0] dist = abs(0 - arr[0]) res = arr[0] for i in range(1, len(arr)): curr = abs(0 - arr[i]) if curr == dist: res = max(res, arr[i]) elif curr < dist: dist = curr res = arr[i] return res arr = [-2, -4, 1, 2 , 8] # 1 # arr = [-2, 1, -1] print(closest(arr)) # 1

    • @tomislam
      @tomislam 57 минут назад

      Could possibly work for a max heap where you drop the heap and create a new one every time there's a new smaller distance.

  • @arintiwari6419
    @arintiwari6419 Час назад

    Memoize

  • @bhuvanachandrag5589
    @bhuvanachandrag5589 Час назад

    If the abs values of nums[i] and abs(closest) are equal, closest can simply be considered as the abs(nums[i]) and returned. Here's my JS code: var findClosestNumber = function (nums) { let closest = nums[0]; for (var i = 1; i < nums.length; i++) { if (Math.abs(nums[i]) < Math.abs(closest )) { closest = nums[i]; } else if (Math.abs(nums[i] == Math.abs(closest ))) { closest = Math.abs(nums[i]); } } return closest ; }

  • @kalyanchatterjee8624
    @kalyanchatterjee8624 3 часа назад

    This is very good. However, for dataframes with categorical / text data, you code will fail with a TypeError. I think this requires fitting only the columns of the dataframe which have numerical values.

  • @patrickbateman6620
    @patrickbateman6620 3 часа назад

    Yet another thing you're asked in coding interviews and will never use in the job. How will a project manager react when he finds out an intern is coding a data structure from scratch?

  • @servantofthelord8147
    @servantofthelord8147 3 часа назад

    Wow. Such a beautiful solution. Excellent work as always Greg!

  • @AffectionateSnowman-vw5iq
    @AffectionateSnowman-vw5iq 3 часа назад

    Bro deserves an Oscar for explaining us time and space complexity just like that I a few minutes ❤❤

    • @GregHogg
      @GregHogg 3 часа назад

      Hahaha thanks buddy

    • @wennwenn1422
      @wennwenn1422 2 часа назад

      ​@@GregHoggThanks Greg

  • @khorshedkhorshed9137
    @khorshedkhorshed9137 3 часа назад

    We can return abs (closest) and avoid using last condition?

    • @paradoxyt1851
      @paradoxyt1851 3 часа назад

      if -1 was the closest, but there was no positive 1 in the array, then it wouldnt work

    • @GregHogg
      @GregHogg 3 часа назад

      Thanks!

  • @PostMeridianLyf
    @PostMeridianLyf 4 часа назад

    Lets gooooo!

  • @ragama623
    @ragama623 5 часов назад

    Im a little confused on what is happening here. From my understanding, the only thing that goes through the hash function is a key. Why would anyone use an array as a key? Doesnt using a key that can change defeat the purpose of a hash map? Can you explain why this is even important?

  • @Arekadiusz
    @Arekadiusz 5 часов назад

    So what's the problem? Sounds easy You do Record/Map in JS or Dictionary in .net, get the result from modulo calculation, check if there is any value in the given array and insert it. But if we need to check whether value is already there, just create another dictionary with string as a key and int as a value. So firstly check if the value already exists in the second dictionary, if not then try to insert the item in the first dictionary (or find the free one) And write the second dictionary value. Easy.

  • @Dogberto999
    @Dogberto999 7 часов назад

    algo comment drop. good content.

  • @viswanathvuppala4526
    @viswanathvuppala4526 8 часов назад

    Hi grg

  • @ungrim97
    @ungrim97 9 часов назад

    The expert dev is the one that realises that your prod code probably wouldn't notice the difference between the two solutions but broke because someone asked if 🤢💛🍇🍊🍌🍍🍎 is an anagram of 🤢🍎💛🍇🍊🍌🍍

  • @RickyRicheRebelle
    @RickyRicheRebelle 9 часов назад

    am i the only one not understanding the question the same way ? "so that both splitted arrays don't contain duplicated numbers" i would interprete it as "the splitted array can't have common value" and such thing happens a lot with me in this kind of interviews. i just find the questions very ambiguous

  • @casperhansen826
    @casperhansen826 9 часов назад

    As I understand it, if index 4 was occupied as well it would pick index 0, and when there was no empty spaces it would loop through the entire list to look for a value that isn't there, sound very complicated to me with lots of traps

  • @RohitSingh-wl5qw
    @RohitSingh-wl5qw 9 часов назад

    How about bucket sorr

  • @sameerlife-jr8bp
    @sameerlife-jr8bp 9 часов назад

    Hello, I'm from Bangladesh. My question, can a data analyst work as a software engineer?

  • @arsheyajain7055
    @arsheyajain7055 9 часов назад

    Awesome

  • @vaibhavsharma6471
    @vaibhavsharma6471 10 часов назад

    Can someone tell if this approach is correct or not? I think we can do it with 2 pointers approach. If there are only 3 integers that we have to account for theek we can have a starting index and a last index. So, 0's are supposed to be swapped to the starting index and the 2's are supposed to be swapped with the last index and then increment the starting pointer and decrement the ending pointer. If we just sort 0 and 2, 1 will automatically be sorted.

  • @ngneerin
    @ngneerin 10 часов назад

    Isn't that used in bloomfilters?

  • @GregHogg
    @GregHogg 10 часов назад

    Subscribe for daily coding videos!

  • @maxjiang1324
    @maxjiang1324 11 часов назад

    Love how simple and stupid Python with all these libraries can be.

  • @harshilsolanki2560
    @harshilsolanki2560 12 часов назад

    𝘾𝙖𝙣 you give me data structure roadmap with example which I have to solve

  • @spirossxz6272
    @spirossxz6272 12 часов назад

    Mergesort -> arr[odd] to arr1, arr[even] to arr2. No?

  • @TheIvasyl
    @TheIvasyl 14 часов назад

    So it's the same as using HashMap, only with hashmap you get a universal solution any number of different colors

  • @vaibhavsharma6471
    @vaibhavsharma6471 14 часов назад

    I think we can do it with 2 pointers approach. If there are only 3 integers that we have to account for theek we can have a starting index and a last index. So, 0's are supposed to be swapped to the starting index and the 2's are supposed to be swapped with the last index and then increment the starting pointer and decrement the ending pointer. If we just sort 0 and 2, 1 will automatically be sorted.

  • @its_code
    @its_code 14 часов назад

    Now i understand mutable and immutable variables ❤❤❤

    • @GregHogg
      @GregHogg 12 часов назад

      Glad to hear it!

  • @patrickbateman6620
    @patrickbateman6620 16 часов назад

    Just use .sort(), it's built in for a reason and it's exactly what every single company would use in production. Assuming you want the lower nunber colours at the start

  • @santhoshm6942
    @santhoshm6942 17 часов назад

    Using three pointers we can solve this problem which is the most optimal solution

  • @maciejmalewicz9123
    @maciejmalewicz9123 18 часов назад

    You can just change the original string to lowercase to avoid the problem with lowercase and uppercase vowels/consonants

  • @qwertyaskwhy
    @qwertyaskwhy 18 часов назад

    never stop please, love you man.

    • @GregHogg
      @GregHogg 17 часов назад

      Hahaha thanks buddy

  • @marcialabrahantes3369
    @marcialabrahantes3369 19 часов назад

    now do it in place! (shifting zeros)

    • @GregHogg
      @GregHogg 17 часов назад

      This is in place, you don't have to "shift" elements for it to be in place, it just means you're overwriting the original array (which we are)

  • @hansmeyer2528
    @hansmeyer2528 19 часов назад

    But why don't they/you use real programming languages? Python is bullshit

    • @SomeCowguy
      @SomeCowguy 14 часов назад

      Because suffering through python code is fun

  • @z3rocool
    @z3rocool 19 часов назад

    this is so basic omg, i instantly thought of this upon seeing this

  • @nif4345
    @nif4345 20 часов назад

    Use the (φ^n - (1-φ)^n)/√5 technique

  • @nif4345
    @nif4345 20 часов назад

    not match deduplicate duplicate

  • @user-iu5yg4xb6l
    @user-iu5yg4xb6l 20 часов назад

    you could just get the answer with math

  • @fusebox9725
    @fusebox9725 20 часов назад

    Basically it's a database with a unique id

  • @bhuvanachandrag5589
    @bhuvanachandrag5589 23 часа назад

    Hi Greg, Thanks for the amazing video and explanation. I have a quick question on the code implementation. On line 12, I do not think the while loop runs more than once. Because we are flipping one zero at a time with the help of the condtion above it (Line 9). Example, if we have flipped 3 zeroes and k = 2 and our intention is to get back one zero (num_zeroes -= 1), we run through the while loop to decrement. But here, after the first iteration of while loop, the condition evaluates to false (2 > 2). This is because we incremented num_zeroes from 2 to 3 (We are flipping one zero at a time). So, my question is to know the intention of selecting a while loop on Line 12. Since, while loop doesn't work for more than one time, I replaced it with a simple if condition. So, Line 12 will become, if (num_zeroes > k): num_zeroes -= 1. The code will still work for all the cases. Here's my code: class Solution: def longestOnes(self, nums: List[int], k: int) -> int: left = 0 max_num = 0 num_of_zeroes = 0 for index, num in enumerate(nums): if num == 0: num_of_zeroes += 1 if num_of_zeroes > k: if nums[left] == 0: num_of_zeroes -= 1 left += 1 max_num = max(max_num, index - left + 1) return max_num

  • @muhammadabdulahadkhan9333
    @muhammadabdulahadkhan9333 День назад

    Omg my teacher made avl trees one of the hardest topics to understand in dsa wish I had discovered this short sooner

  • @SanteeRocks
    @SanteeRocks День назад

    Why aren’t you a CEO then 😅

  • @P.Shivakrishna
    @P.Shivakrishna День назад

    Just do in js nums.sort((a, b) =>a-b) it is o(n)

  • @yash-uy5ym
    @yash-uy5ym День назад

    What kind of monster makes curly brackets like that?

  • @damonpalovaara4211
    @damonpalovaara4211 День назад

    @19:20 Can somebody explain to me what out[:, -1, :] does. I'm trying to learn the burn crate for Rust which is young and doesn't have enough documentation so I'm stuck referencing pytorch which is it's influence.

  • @Trippze
    @Trippze День назад

    is he cracking his voice on purpose?