LeetCode 697. Degree of an Array (Algorithm Explained)
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
You probably do the best job of explaining on CZcams leetcode problems
Non-negative is not a synonym for positive; they use that wording to allow for the inclusion of zeros.
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!!
After trying, at the end I come to you because I know I will definitely get my answer. Your a genius
Nick, I appreciate your help and effort you put creating these videos for us. Thank you
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
Thank you, Nick, the way you explained the solution was really nice and clear
Finally you made me understand this problem, weird one, but your explanation is totally cool. Thanks a lot!
Great video, awesome content !! Thanks for sharing.
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
like your explanation thanks a lot :)
another great one !
bro nice job...
non-negative means it can contain zero and positive means no.s above zero
Thanks a lot for all these videos. I have a request.
Can you post problem 950 Reveal cards in Increasing order please.
Thanks a lot!!!
Still acing it.....kudos👌
Great !!!!!!!!! Love from INDIA
can you please use c++ as well ?
Thanks a lot sir
Hehe solved my first problem tdy :D
thanks
Yes, given a populated array of positive integers.....Was that so hard for the fine folks at Leetcode?:)
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.
great explanation
Thanks dude
@@NickWhite Does she looks like a dude?
I believe min_length should be initialized to 1. What if we have just one element in an array?
holy sht, this is not easy but medium problem!
Awesome
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.
I thought the same ,as we think in python, I guess.
why some problems r hheavily downvoted
I don't understand the second part.