LeetCode 697. Degree of an Array (Algorithm Explained)

Sdílet
Vložit
  • čas přidán 23. 09. 2019
  • The Best Place To Learn Anything Coding Related - bit.ly/3MFZLIZ
    Join my free exclusive community built to empower programmers! - www.skool.com/software-develo...
    Preparing For Your Coding Interviews? Use These Resources
    --------------------
    (My Course) Data Structures & Algorithms for Coding Interviews - thedailybyte.dev/courses/nick
    AlgoCademy - algocademy.com/?referral=nick...
    Daily Coding Interview Questions - bit.ly/3xw1Sqz
    10% Off Of The Best Web Hosting! - hostinger.com/nickwhite
    Follow My Twitter - / nicholaswwhite
    Follow My Instagram - / nickwwhite
    Other Social Media
    ----------------------------------------------
    Discord - / discord
    Twitch - / nickwhitettv
    TikTok - / nickwhitetiktok
    LinkedIn - / nicholas-w-white
    Show Support
    ------------------------------------------------------------------------------
    Patreon - / nick_white
    PayPal - paypal.me/nickwwhite?locale.x...
    Become A Member - / @nickwhite
    #coding #programming #softwareengineering
  • Věda a technologie

Komentáře • 34

  • @sicko_drops
    @sicko_drops Před 4 lety +16

    You probably do the best job of explaining on CZcams leetcode problems

  • @LoganKearsley
    @LoganKearsley Před 4 lety +27

    Non-negative is not a synonym for positive; they use that wording to allow for the inclusion of zeros.

  • @vcfirefox
    @vcfirefox Před 2 lety

    dude i read the question like 10 times and then decided to watch someone explaining that.. watched yours and it struck me like in 1minute 38 seconds. thanks!!

  • @biswamohandwari6460
    @biswamohandwari6460 Před 3 lety +1

    After trying, at the end I come to you because I know I will definitely get my answer. Your a genius

  • @rahulratra6672
    @rahulratra6672 Před 4 lety

    Nick, I appreciate your help and effort you put creating these videos for us. Thank you

  • @mytommy
    @mytommy Před 4 lety +10

    can u do videos on system design questions (common qs like how to design Instagram, etc)? i searched ur videos and havent found any i think viewers would appreciate those kind of videos. and keep it up

  • @sureshgarine
    @sureshgarine Před 2 lety

    Thank you, Nick, the way you explained the solution was really nice and clear

  • @harpercfc_
    @harpercfc_ Před 2 lety

    Finally you made me understand this problem, weird one, but your explanation is totally cool. Thanks a lot!

  • @pawandeepchor89
    @pawandeepchor89 Před rokem

    Great video, awesome content !! Thanks for sharing.

  • @hassansmallah
    @hassansmallah Před 4 lety +1

    Thank you
    Python:
    class Solution:
    def findShortestSubArray(self, nums: [int]) -> int:
    num_counts = {}
    first_seen = {}
    min_length = 0
    degree = 0
    for i in range(len(nums)):
    first_seen[nums[i]] = first_seen.get(nums[i], i)
    num_counts[nums[i]] = num_counts.get(nums[i], 0) + 1
    if (num_counts[nums[i]] > degree):
    degree = num_counts[nums[i]]
    min_length = i - first_seen[nums[i]] + 1
    elif num_counts[nums[i]] == degree:
    min_length = min(min_length, i - first_seen[nums[i]] + 1)
    return min_length

  • @jackwang8105
    @jackwang8105 Před 4 lety +1

    like your explanation thanks a lot :)

  • @MrThepratik
    @MrThepratik Před 4 lety

    another great one !

  • @rishabhgupta6774
    @rishabhgupta6774 Před 3 lety +1

    bro nice job...
    non-negative means it can contain zero and positive means no.s above zero

  • @NitishDobhal281
    @NitishDobhal281 Před 4 lety +2

    Thanks a lot for all these videos. I have a request.
    Can you post problem 950 Reveal cards in Increasing order please.

  • @mahalakshmithirumurthy2631

    Thanks a lot!!!

  • @samyakjain6855
    @samyakjain6855 Před 4 lety

    Still acing it.....kudos👌

  • @sukhdevsharma5611
    @sukhdevsharma5611 Před 3 lety

    Great !!!!!!!!! Love from INDIA

  • @someone-zi8xc
    @someone-zi8xc Před 3 lety

    can you please use c++ as well ?

  • @amrholo4445
    @amrholo4445 Před 2 lety

    Thanks a lot sir

  • @jxvisn8551
    @jxvisn8551 Před 4 lety

    Hehe solved my first problem tdy :D

  • @rashedulislam9301
    @rashedulislam9301 Před 4 lety

    thanks

  • @user-mn3iq2cs9n
    @user-mn3iq2cs9n Před 4 lety +1

    Yes, given a populated array of positive integers.....Was that so hard for the fine folks at Leetcode?:)

    • @user-mn3iq2cs9n
      @user-mn3iq2cs9n Před 4 lety +1

      ps. Great explanation. Wierd problem for a newbie, and this one of the best explanations I've heard on your channel so far. I really appreciate it.

  • @atefe3919
    @atefe3919 Před 4 lety +2

    great explanation

  • @GauravDG1990
    @GauravDG1990 Před 3 lety +3

    I believe min_length should be initialized to 1. What if we have just one element in an array?

  • @borat_trades2860
    @borat_trades2860 Před 4 lety +2

    holy sht, this is not easy but medium problem!

  • @sukhdevsharma5611
    @sukhdevsharma5611 Před 3 lety

    Awesome

  • @jjferman2587
    @jjferman2587 Před 4 lety +1

    Couldn’t you use a single HashMap? Not sure how it works in Java but you could maybe use a tuple to store the count and first seen as the value in a single hash table.

    • @amritbol
      @amritbol Před 4 lety +1

      I thought the same ,as we think in python, I guess.

  • @ajourney179
    @ajourney179 Před 4 lety

    why some problems r hheavily downvoted

  • @supremoluminary
    @supremoluminary Před 3 lety

    I don't understand the second part.