as someone learning through neetcode, this problem didn't really belong under the kadane's algo section. It had less to do with kadane's algo itself and more to do with sliding window or 2 pointers.
@NeetCodeIO Жыл бұрын
Today's daily LC is already on the main channel (kzbin.info/www/bejne/Z6HOgJqOeZtmr7c), so uploading another one instead today.
@ary_21 Жыл бұрын
I thought it's gonna be a holiday today , appreciate your dedication
@krakenjoka Жыл бұрын
Actually from this explanation, variables tracking max and cur length would be enough. On sliding window problems we usually need the left pointer to check for some conditions. But on this problem it's not that relevant. Thanks for these videos
@alexl2512 Жыл бұрын
My implementation def maxTurbulenceSize(self, arr: List[int]) -> int: l = 0 maxLen = 0 preS = "=" for r in range(len(arr)): if r == 0: maxLen = 1 continue if arr[r - 1] < arr[r] and preS != "": preS = ">" maxLen = max(maxLen, r - l + 1) elif arr[r - 1] == arr[r]: l = r preS = "=" else: l = r - 1 return maxLen
@rafael8410 ай бұрын
I think this solution is a bit more easy to read: var maxTurbulenceSize = function (arr) { if (arr.length curr ? 1 : -1; if (newSign === sign) { currCount = 2; } else { currCount += 1; } sign = newSign; } maxCount = Math.max(maxCount, currCount); } return maxCount; };
@trueknowledge1981 Жыл бұрын
Holy I am the first this time Hello Neetcode
@iamnoob75933 ай бұрын
Thanks neetcode
@junjason411411 ай бұрын
My solution to this problem. class Solution: def maxTurbulenceSize(self, arr: List[int]) -> int: if len(arr) == 1: return 1 pre_diff, subarray_len = -(arr[0] - arr[1]), 1 longest = subarray_len for i in range(1, len(arr)): cur_diff = arr[i - 1] - arr[i] if cur_diff * pre_diff < 0: subarray_len, pre_diff = subarray_len + 1, cur_diff continue longest = max(longest, subarray_len) subarray_len = 1 if cur_diff == 0 else 2 pre_diff = cur_diff return max(longest, subarray_len)
@EzraSchroeder Жыл бұрын
@5:07 math died!!!! XD hahahahahaha!!!!!
@sumitsharma6738 Жыл бұрын
also for famous problem "OPTIMAL STRATEGY FOR A GAME"
@vivekmit06 Жыл бұрын
Thank you very much!!!
@sumitsharma6738 Жыл бұрын
please make a video for "Super Egg Drop" problem
@Mohit-uq7hq3 ай бұрын
he sounds like john smilga from free code camp
@menagamal7239 Жыл бұрын
Can't we Just Use Stacks for this one ?
@BCS_AAMIRASHRAF Жыл бұрын
❤❤❤❤❤
@trueknowledge1981 Жыл бұрын
bdw what is use of left pointer exacltly?
@MeanSoybean Жыл бұрын
to keep track of the beginning of the currently examined candidate for turbulent subarray
@krakenjoka Жыл бұрын
I dont think it's necessary, 2 variables, one counting current length and another for max length would be enough
@MeanSoybean Жыл бұрын
@@krakenjoka and how would you compute what the current length is
@krakenjoka Жыл бұрын
@@MeanSoybean current length initial value can be 0, then during the for loop, add cur+=1 if it satisfy our condition. Otherwise reset it to 0 or 1 depending on stones[i-1] and stones[i] being equal or not. At every iteration compare global max so far to the current length.
@nehatyagi5218 Жыл бұрын
hey can you debug my code class Solution { public: int maxTurbulenceSize(vector& arr) { int l =0; int r = 1; int ans =1; int n = arr.size(); string prev = ""; while(r arr[r] && prev != ">"){ ans = max(ans , r-l+1); r += 1; prev = ">"; } else if(arr[r-1] < arr[r] && prev != "
@isseihyodou7111 Жыл бұрын
The issue with your code lies in how it's handling the case where the array elements are equal (arr[r] == arr[r-1]). The logic doesn't correctly reset the pointers l and r, resulting in incorrect computations for the turbulent subarray length. Here's a modified version of your code that addresses this issue: public: int maxTurbulenceSize(vector& arr) { int l = 0; int r = 1; int ans = 1; int n = arr.size(); string prev = ""; while (r < n) { if (arr[r - 1] > arr[r] && prev != ">") { ans = max(ans, r - l + 1); prev = ">"; } else if (arr[r - 1] < arr[r] && prev != "