Divide Array Into Arrays With Max Difference - Leetcode 2966 - Python

  Рет қаралды 11,304

NeetCodeIO

NeetCodeIO

Күн бұрын

🚀 neetcode.io/ - A better way to prepare for Coding Interviews
🧑‍💼 LinkedIn: / navdeep-singh-3aaa14161
🐦 Twitter: / neetcode1
⭐ BLIND-75 PLAYLIST: • Two Sum - Leetcode 1 -...
Problem Link: leetcode.com/problems/divide-...
0:00 - Read the problem
0:10 - Drawing Explanation
4:38 - Coding Explanation
leetcode 2966
#neetcode #leetcode #python

Пікірлер: 26
@julianelmasry9556
@julianelmasry9556 5 ай бұрын
NO WAY. HELLA EFFICIENT EASTER EGG ACTUALLY GOT DROPPED
@shreehari2589
@shreehari2589 5 ай бұрын
What Easter egg are you talking about?
@dong-hanguyen8266
@dong-hanguyen8266 5 ай бұрын
class Solution: def divideArray(self, nums: List[int], k: int) -> List[List[int]]: # Sort the nums nums.sort() # O(nlogn) ans = [] low = float('-inf') split = [] # Runs through O(n) for each index in nums for i in range(len(nums)): # Sets the low if low == float('-inf'): low = nums[i] # Checks difference if abs(low - nums[i]) > k: return [] else: split.append(nums[i]) # Adds to ans array if len(split) == 3: ans.append(split) split = [] low = float('-inf') # Checks lens if len(split) == 0: return ans His solution was so simple 😢This is why I failed my FAANG interviews...
@mnaresh3382
@mnaresh3382 5 ай бұрын
Finally something that I could solve myself efficiently, definitely seeing some improvement, thanks neetcode
@AMakYu
@AMakYu 5 ай бұрын
Hella efficient 👌
@ooouuuccchhh
@ooouuuccchhh 5 ай бұрын
Me waking up at 7:30 in this winter morning to find the first video as neetcode video
@CrabGuyy
@CrabGuyy 5 ай бұрын
you and me both, brother
@Onyaga
@Onyaga 5 ай бұрын
This solution is quite trivial i thought it was an easy problem and was racking my head trying to think of a better, O(n) soln. The example literally gives a big hint that the answer will be an arrangement of sorted elements
@a_maxed_out_handle_of_30_chars
@a_maxed_out_handle_of_30_chars 5 ай бұрын
thanks, i knew it had something to do with sorting but couldn't solve further
@feazysil2707
@feazysil2707 5 ай бұрын
next time you got this!
@Aliennnaa
@Aliennnaa 5 ай бұрын
yeah i solved after struggling for one hour or so and checked comments on leetcode and got discouraged T_T .
@nameless2850
@nameless2850 5 ай бұрын
I didn't the constraint of size 3 and was over complicating by sorting + dp
@sprajosh
@sprajosh 5 ай бұрын
I thought you've already made a video on this question
@hemanth.alluri
@hemanth.alluri 5 ай бұрын
Honest question: how is this a medium?
@TrickyCat
@TrickyCat 5 ай бұрын
@NeetCodeIO I wonder since when Python does deep copy in this case: kzbin.info/www/bejne/jp3IgJylZtR9m9E That's a shallow copy, dude: ```python a = [1] l1 = [a] l2 = l1[0:] l2[0].append(42) print(a) print(l1) print(l2) ``` If the copy was "deep" it would create the separate subcollections (sublists in the case above), but as the example shows, the list (which `a` points to) is being reused
@SanketBhat7
@SanketBhat7 5 ай бұрын
But for me this was the initial approach. But I kept thinking there must be some O(n) solution, but there isn't!!!
@garsidrag
@garsidrag 5 ай бұрын
hell satisfying outro !
@kunwarankush6030
@kunwarankush6030 5 ай бұрын
From the question description, there are 2 condiditions that every array must satisfy. Majority of the solutions cater to the condition of difference of two elements in an array to be
@GarethNgFilms
@GarethNgFilms 5 ай бұрын
The wording is a bit confusing, but what they mean is that each instance of a number has to be in one of the subarrays. It's ok if the value appears in multiple
@aaronhodgins6134
@aaronhodgins6134 5 ай бұрын
we hella efficient
@chrischika7026
@chrischika7026 5 ай бұрын
This wa easy
@jonathandiaz8186
@jonathandiaz8186 5 ай бұрын
"hella efficient" lmfao. Haven't heard that word in hella long
@kunwarankush6030
@kunwarankush6030 5 ай бұрын
Can any one explain condition 1st ...
@youssefb.7406
@youssefb.7406 5 ай бұрын
I Could not even understand the problem title
@theshlok
@theshlok 5 ай бұрын
Out of Boundary Paths - Leetcode 576 - Python
18:20
NeetCodeIO
Рет қаралды 15 М.
Find the Difference of Two Arrays - Leetcode 2215 - Python
7:34
Children deceived dad #comedy
00:19
yuzvikii_family
Рет қаралды 8 МЛН
ОДИН ДЕНЬ ИЗ ДЕТСТВА❤️ #shorts
00:59
BATEK_OFFICIAL
Рет қаралды 9 МЛН
I Can't Believe We Did This...
00:38
Stokes Twins
Рет қаралды 82 МЛН
Shift 2D Grid - Leetcode 1260 - Python
10:18
NeetCode
Рет қаралды 19 М.
Furthest Building You Can Reach - Leetcode 1642 - Python
11:08
NeetCodeIO
Рет қаралды 14 М.
Prefix Sums - Problems, Code in C++ & Python
20:51
Errichto Algorithms
Рет қаралды 43 М.
Sequential Digits - Leetcode 1291 - Python
15:02
NeetCodeIO
Рет қаралды 12 М.
I gave 127 interviews. Top 5 Algorithms they asked me.
8:36
Sahil & Sarra
Рет қаралды 614 М.
Daily Temperatures - Leetcode 739 - Stacks (Python)
12:35
Greg Hogg
Рет қаралды 1,5 М.
Subarray Sums Divisible by K - Leetcode 974 - Python
16:41
NeetCodeIO
Рет қаралды 12 М.
Maximum Total Importance of Roads - Leetcode 2285 - Python
9:59