High Definition Standard Definition Theater
Video id : bFBDUty4la4
ImmersiveAmbientModecolor: #bbbcb2 (color 2)
Video Format : (720p) openh264 ( https://github.com/cisco/openh264) mp4a.40.2 | 44100Hz
Audio Format: 140 ( High )
PokeEncryptID: 9224ed0ef96ae8ccd610e46e717713ae78d7f6f01d459fd91bcfbad9fd088ca25f5c23adf00c507ce95b70ffb3ded760
Proxy : cal1.iv.ggtyler.dev - refresh the page to change the proxy location
Date : 1732406627877 - unknown on Apple WebKit
Mystery text : YkZCRFV0eTRsYTQgaSAgbG92ICB1IGNhbDEuaXYuZ2d0eWxlci5kZXY=
143 : true
Split the Array - Leetcode 3046
 60 FPS video
229,105 Views • Oct 16, 2024 • Click to toggle off description
Split the Array - Leetcode 3046
Metadata And Engagement

Views : 229,105
Genre: Education
Uploaded At Oct 16, 2024 ^^


warning: returnyoutubedislikes may not be accurate, this is just an estiment ehe :3
Rating : 4.755 (483/7,401 LTDR)

93.87% of the users lieked the video!!
6.13% of the users dislieked the video!!
User score: 90.81- Overwhelmingly Positive

RYD date created : 2024-11-23T19:11:14.676742Z
See in json
Tags
Connections
Nyo connections found on the description ;_; report an issue lol

93 Comments

Top Comments of this video!! :3

@GregHogg

1 month ago

Master data structures and algorithms for FREE at algomap.io/ :)

10 |

@DaBestNub

1 month ago

my left ear really enjoyed this video

635 |

@ammartahir86

1 month ago

I had only one earbud in. Thanks for the subtitles.

90 |

@random4573

1 month ago

If array is sorted then we don't even have to create counters. Just iterate over array and at any point same number is repeated more that 2, you can return false

104 |

@zoltan367

1 month ago

my right ear feels alone

64 |

@lukesanford9026

5 days ago

I dont think ive ever seen/used a counter and ive been casually programming in python for years, goes to show how much I still have to learn

|

@ShortFilmVD

3 weeks ago

Is this the most efficient solution?

Building up a dictionary and then building the two solution arrays from that seems like it could be more costly vs using two sets and checking for inclusion before insert, which would allow for the earliest return on success or failure.

5 |

@SlayCC

1 month ago

What is this audio i thought my speakers were broken

19 |

@danielhod53

1 month ago

If the array is sorted you can do a for loop to check if x[i] = x[i+1] and then increase i by 2 to skip the number you compared to

6 |

@Modslover

3 weeks ago

Id compare a list to a set.

2 |

@Kargalagan

3 weeks ago

I thought i was gping crazy for only hearing the click.mp3

2 |

@iOnlySay

1 month ago

when do you even need to solve those? i mean in real life not in an interview?

8 |

@S-we2gp

3 weeks ago

This was the only question ive ever got on my own lmao.

1 |

@ericcartman2294

1 month ago

Why doesn't the result make any sense with the question? Question was to split the array of numbers into 2 arrays? And make sure arrays doesn't have duplicates. In the result we have boolean answer from iteration of hash set and by checking if the number is greater than 2.
I feel dumb.

4 |

@mauricioguerrero8890

1 month ago

We can apply the pigeonhole principle to determine whether it's possible to split an array into two subarrays such that each subarray contains distinct elements. The pigeonhole principle states that if you have more "pigeons" than "holes," then at least one "hole" must contain more than one "pigeon."

In this context, the "pigeons" are the occurrences of each number in the array, and the "holes" are the two subarrays. If any number appears more than twice in the array, it’s impossible to split the array into two subarrays where each number appears only once in each subarray. Therefore, if any number’s frequency is greater than 2, we can immediately conclude that it’s not possible to split the array in this way, and return False. Otherwise, we return True.

Below is an implementation of this:

# Create a frequency counter for each value in frequency_counter = { }

# Iterate over the nums list and update frequencies
# in the counter

for num in nums:
# If no (key, value) pair exists,
# set the default value to 0

# and increment

frequency_counter[num] = 1 + frequency_counter.get(num, 0)

# Check if any frequency exceeds 2, return False if so


for frequency in frequency_counter.values():

if frequency > 2:
return False

return True



EDIT: You can just immediately check if the current number's frequency is greater than 2 and immediately return False if it is.


for num in nums:
# If no (key, value) pair exists, set the default value to 0
# and increment

frequency_counter[num] = 1 + frequency_counter.get(num, 0)

if frequency_counter[num] > 2:
return False

return True

4 |

@jacksonsingleton

1 week ago

Had a question just like this for an amazon interview

|

@mamuli01

1 month ago

this falls under dsa right ?

|

@vinitchauhan5047

3 weeks ago

We can do XOR of all elements, if each number is repeated in a multiple of 2, then we will get 0 at the end.

|

@kurtlee138

1 month ago

Stop calling these questions dumb, we dont want them any harder

3 |

@razuepic

2 weeks ago

Lol, I just did this

list1: list = [1, 1, 2, 2, 3, 4]

list2: list = [list1[0], list1[2], list1[4]]

list3: list = [list1[1], list1[3], list1[5]]

print(list2, list3)

Idc if it's inefficient I just did it on my phone in like 2 minutes.

1 |

Go To Top