You don't even need to count the whole array. You can return False early if you hit a higher number
2024-03-16 17:08:31
233
Its_the_doolster :
simply loop through and count occurence of the current num. If that count becomes 3 return false else true.
2024-03-17 20:43:03
25
Furt_Tech Industries :
still got it wrong dammit im cooked
2024-04-09 02:08:03
64
Liv :
Could also create 2 sets, then foreach item, if not in the 1st set, add it, else if not in 2nd set add it, else return false, return true at end of loop. Basically the same answer, I just like sets :3
2024-05-26 06:47:53
1
pettertrippein :
this is actually an interesting problem
2024-04-08 18:16:26
28
😅🤓 :
After discrete math, coding has been so much easier to understand and code
2024-04-19 09:14:49
1
evananan3 :
just sort the list, if nums[i] = num[i+2] then it's not possible. Definitely not the fastest approach, but one of the simplest
2024-03-19 21:11:53
2
Victor :
This is a great question for an interview. Simple, yet with many possible solutions and follow ups.
2024-04-09 00:02:12
8
lukehebb :
This isn’t a coding question. This is a thinking question
2024-04-08 04:28:40
3
Armetron :
it wasn't specified, but if the array is already pre-sorted you don't even need to count. you can just start at index 2 and compare it to i-2. If they match return false
2024-05-07 16:35:41
11
Borisas :
U dont even need to do that, just have a hashset and if it already contains a value u want to add return false.
2024-05-04 07:24:42
1
mindthunderbolt :
okay but how do I get the arrays themselves? we need your help programmer man😅
2024-05-01 21:56:54
0
Ishaan :
I don't think it's a dumb question, it's a cool thought process. Also you can more concisely express the idea as return max(counter.values()) <= 2
2024-04-29 04:49:09
0
iiridial :
why iterate, max(counter.values()) is better
2024-04-11 18:35:25
0
⚜DAMON MEDEK & the Dead Dolls⚜ :
is JS I think you could do new Set(array). that will only keep unique items.
2024-04-07 02:59:48
1
appleuser36838358 :
Len Vs Set Length if Len(list) > 2*len(set(list))
2024-03-19 04:24:15
22
Enigma :
how can I get so smart to think like this 😂
2024-04-09 02:33:37
0
Moy :
Tbh I feel like this one would have a lot of follow ups and discussion of trade offs especially for space complexity. Just like how two_sum is easy until they ask ya to solve it in different ways.
2024-03-18 22:42:30
3
harliy quin :
do it in c if you are good enough
2024-04-07 00:12:06
5
Tom Sibson :
In mathematics, this is known as the pigeonhole principle.
2024-04-11 21:11:03
0
Adospassos :
Often times there is no preset question and engineers just pick what to ask
2024-04-09 22:32:07
0
kamil :
just use a set and return once there is a duplicate?
2024-04-09 19:50:16
0
Derradji :
if (number from array is in array1) : add to array2; else : add to array1
2024-04-20 13:31:13
0
NecRock :
This doesn't seem like a "can you solve this" question but a "how do you solve this" question. Do you stick something naive or go for something more optimal? Do you ask questions?
2024-05-19 14:04:21
0
adrtaz :
Accumulator pattern?
2024-05-01 04:30:13
0
To see more videos from user @greghogg5, please go to the Tikwm
homepage.