How would you personally solve the problem in picrel?

How would you personally solve the problem in picrel?
I would:
1. Choose the smallest array.
2. Create a hashtable mapping all the elements of this array to false.
3. For each element of the second array: if it's in the hashtable, set it to true.
4. For each element of the third array: if it's in the hashtable and set to true, return true. If the loop finished without this condition getting triggered, return false.

Attached: 7i1lvije90by.png (542x497, 52.6K)

> please do my homework for me
no.

Certainlky not like OP cause it does not do what its supposed to do. (It would fail if the arrays were 123 456 781, for example) I would have a master array and then the other 2 as slave arrays. First, I splice the 2 slave arrays toghether. Then I pick the first element in the master array, and then I iteratively compare it to the elements of this spliced array. The moment there is an element equal to element number i, you return false. If you manage to finish it without getting to false, then return true.

>sort all 3
>grab first element of each list and store largest value as threshold
>check against final element of other two lists
>if your threshold is still larger than final elements, break
>otherwise binary search the other lists to the closest value as your threshold
>then iterate until one of your lists finishes

It is a horrible solution though. Literally read the post above you you god damn midwit.
I can't believe you niggers.

So you basically iterate through the sorted arrays in a similar way to merge-sort (but without actually storing anything), except you use an optimization to finish earlier if the arrays' ranges of values are significantly different? Nice solution then.

use python sets

In C# this is just !groupA.Intersect(groupB).Intersect(groupC).Any()

What's the time complexity of the implementation? Which method does it use?

This is actually ridiculously slow compared to OP

Please tell me op's solution is a decent one, that's the only solution I can think of

I don't give a fuck nerd, I just collect my paychecks. Joking aside, in my experience Linq queries are very well optimized so unless you expect your code to be running on a toaster my solution would get the job done and has the added benefit of actually being easily readable vs some retarded algorithm that takes 10+ minutes to grok.

array_diff()

Attached: honkler-nigger.jpg (524x512, 35.38K)

a thousand nerds way smarter than you already took care of optimizing linq so that i can use high level functions without a care in the world
>What's the time complexity of the implementation?
fast enough
>Which method does it use?
a good one

If memory isn't a concern (I don't know if it's faster than OP's solution)
>make an empty dictionary
>for each array, each element in the array is a new key in that dictionary if no key exists
>each value for each key is a list of 3 numbers
>each number corresponds to the frequency for each value for each corresponding array
>when all 3 arrays have been added to the dictionary, go through each key
>if one key has a frequency of at least 1 for all 3 arrays, then return false
>otherwise return true at the end of the loop

Again I don't know if it's any better I'm just thinking of an alternate way of doing it

fn no_common(a,b,c) {
temp = [ a, b, c ].sort_by(fn(x) { size(x) })
x = temp[0]
y = temp[1]
big = temp[2]

seen_x = Set{}
seen_y = Set{}

for _, idx in big {
seen_x.add(x.get(idx))
seen_y.add(y.get(idx))
}

for z, _ in big {
// can copy-paste this line back into the original loop as well but won't change time-complexity for the worst case (the only case that matters)
if seen_x[z] and seen_y[z] { return false }
}
}

Made up syntax, .get wont throw out of bound exception. (like poothon IIRC) Not sure if it can go below 2n because an element from A may be in B and C but not seen yet and there's no way to know which elements this would be the case for without sorting the data first but sorting adds time-complexity too. 2n is still linear though so seems OK

This guy knows the truth. I once too was like this kid from the OP, constantly grinding my mind with tinkering the fuck out of each and every petty algos / programming 101 assignment and even transferring that habit to my early days at work. That was until I realized ofc that all this is highly punishable and frowned upon by both carma and my superiors.

D=common( A,B)
E=common(D,C)
return !(|E| > 0)

>It would fail if the arrays were 123 456 781, for example
No, it wouldn't.

Just make a mutable set and add elements from each array. If the element already exists in the set then there are duplicates.

fails if one array has duplicate elements lol

just count the occurences
from itertools import chain
l1 = [1,2,3]
l2 = [3,6,9]
l3 = [3,33,333]
m = {}
for x in chain(l1,l2,l3):
t = m[x] = m.setdefault(x, 0) + 1
if t > 2:
print("common element", x)
break
else:
print("no common element")

(groupA & groupB & groupC).size == 0


that was fucking easy

unordered_set insert has an average complexity of O(1)
So convert all arrays to sets = O(N)
unordered_set find also is O(1), just iterate over all 3 sets and check if the value is in both others, which is still O(N)

There might be better solutions, but this one is still straight forward enough.

see

Or actually:
Use a hashmap with the number as key, and the count as value.
Iterate over all 3 arrays, increment the cound in the hashmap for each number.
At the end iterate over the hash map and see if for any key the count is == 3.

Works for any number N of arrays. Take the (N-1) longest arrays and turn them into sets so that you can efficiently decide membership. It may actually be even better to have a single map that stores (N-1) booleans for each element, although it will depend on how many duplicates you expect to see on average. Then loop through the elements in the shortest array and check for membership in each of the sets.

>Take the (N-1) longest arrays and turn them into sets
Is that a full loop for each array that is being converted?

It's pretty bad. You have 3 nested loops, so basically O(n^3)
Imagine the vectors being 1 million elements long each, then you might have to do 1m * 1m * 1m iterations.

What the fuck are you talking about, everyone knows linq runs like ass

right didn't think about that. easy enough to fix though
def disjoint1(l1,l2,l3):
m = {}
for l in [l1,l2,l3]:
seen = set()
for x in l:
if x in seen:
continue
seen.add(x)
t = m[x] = m.setdefault(x, 0) + 1
if t > 2:
return False
return True

print(disjoint1([3,3,3],[3],[4,5,6])) # True
print(disjoint1([3,3,3],[3],[4,5,3,6])) # False

The description is confusing but the function name says "disjoint" and you get three arrays.
So I would check
A vs. B
if they're disjoint then
A vs. C
if they're disjoint then
B vs. C
if they're disjoint then return true

And if one of the conditions fails return false and exit without checking further.

Attached: 1658455258473.png (737x537, 17.53K)

Honestly my understanding of implementations of hashtables is kind of bad but is it really the equivalent of 3 nested loops?

>right didn't think about that. blahblah-
you already failed the interview