Longest Consecutive Sequence - LeetCode 128 - Java

  Рет қаралды 1,530

LeetCode University

LeetCode University

Күн бұрын

Пікірлер
@suggestaname1685
@suggestaname1685 2 жыл бұрын
I swear that you provide one of the highest, if not the highest, quality explanations on KZbin! Thank you so much for this. I understood each problem you uploaded on this channel completely!
@LeetCodeUniversity
@LeetCodeUniversity 2 жыл бұрын
Thank you so much! I am so glad that I’m providing value to you. I will always upload the highest explanations on KZbin!
@balu6923
@balu6923 2 жыл бұрын
Thank you for taking the time to do this. I saw your post on reddit and came over to check out the channel! Great work and goodluck.
@LeetCodeUniversity
@LeetCodeUniversity 2 жыл бұрын
Thank you so much for the support and I am so glad that I am providing value to you!
@HarshitShrivastava14
@HarshitShrivastava14 2 жыл бұрын
You could use a regular for loop (int i = 0; i < nums.length;) instead of the foreach loop and increment the loop control variable, `i` after you have incremented the length and similarly in an else case - this way you can directly skip the numbers in the outer loop where you do not see a sequence starting and getting a better runtime.
@LeetCodeUniversity
@LeetCodeUniversity 2 жыл бұрын
Yes that is correct, thank you!
@anishaa3298
@anishaa3298 Жыл бұрын
thank you so much!!!!!!!!!!!!!!!! super easy to understand :)
@LeetCodeUniversity
@LeetCodeUniversity Жыл бұрын
Thank you!!
@floatingfortress721
@floatingfortress721 2 жыл бұрын
Approach #3: For an array with duplicates e.g. nums = [0, 0, 0, 1, 4, 3, 2] we'd generate the sequence three times!
@LeetCodeUniversity
@LeetCodeUniversity 2 жыл бұрын
That is correct. Since there is nothing smaller than 0 it will be the start of a sequence and thus we need to check the sequence generated by it. Now we have 3 0’s, so we will generate 3 exact sequences of the same length, but that length is the answer. In this case length=4
@mirriammaina6860
@mirriammaina6860 10 ай бұрын
Isn't time complextity worst case scenario? Worst case for this code is 2 loops for each num without a sequence since we always start at num + 0. I don't understand how this is O(n) time complexity
@wajihakhan8618
@wajihakhan8618 Жыл бұрын
why you used while loop in line 11 can you explain this?
Product of Array Except Self - LeetCode 238 - Java
28:54
LeetCode University
Рет қаралды 2 М.
I thought one thing and the truth is something else 😂
00:34
عائلة ابو رعد Abo Raad family
Рет қаралды 14 МЛН
Sigma Kid Mistake #funny #sigma
00:17
CRAZY GREAPA
Рет қаралды 14 МЛН
Lamborghini vs Smoke 😱
00:38
Topper Guild
Рет қаралды 53 МЛН
How to Fight a Gross Man 😡
00:19
Alan Chikin Chow
Рет қаралды 20 МЛН
Leetcode 128 - LONGEST CONSECUTIVE SEQUENCE
9:24
NeetCode
Рет қаралды 393 М.
Rotate Image - LeetCode 48 - Java
24:51
LeetCode University
Рет қаралды 1,3 М.
Longest Consecutive Sequence | Leetcode(Hard) | GooGLe
13:47
take U forward
Рет қаралды 145 М.
Maximum Subarray - LeetCode 53 - Java | Kadane's Algorithm
18:21
LeetCode University
Рет қаралды 1,4 М.
Flutter Engage
3:58:21
Flutter
Рет қаралды 2 МЛН
Sum of Two Integers - LeetCode 371 - Java
23:12
LeetCode University
Рет қаралды 1,2 М.
LeetCode 128 "HARD" - Longest Consecutive Sequence
10:10
Nick White
Рет қаралды 36 М.
I thought one thing and the truth is something else 😂
00:34
عائلة ابو رعد Abo Raad family
Рет қаралды 14 МЛН